ChatCrawlersearch across public Telegram Open the app
Q

Qt for Python (PySide/Shiboken)

7 August 2021
2021-08-07×
7 August 2021
R
Hi, all! I'm trying to create and use a custom Qml module. The docs are confusing as regard to: - create the import Paths. - create the module structure (i.e: paths, qmldir file) - how to import them. I either get to results: module "Example" is not installed or (if I use paths) that a property (that exists and is set) is undefined. If anyone has any step-to-step, I'd appreciate. To import/install module I tried adding a env. variable with the path to the module and adding it to the project.pro file. Neither seems to do any difference.
1. Try to have qml file one directory, and all the file under that directory could be importable in any file on that directory, this is the first thing to know. ie: mod{file1.qml, file2.qml} 2. In the parent directory you could have qml file, and you are able to load custom qml file under mod/ directory, like this the mod/ is the custom which is importable like this after import QtQuick 2.0, add import "mod". 3. That is it.
let me show you an example on project i did
Фотография
click to show
this is the main.qml file.
Фотография
click to show
see on the left and right, directory are imported as a custom qml module in the main.qml file
I tried @bayangp0 suggestions, but I still got "undefined" when accessing the property I want.
this is the directory structure with the Qml files:
Файл
image_2021-08-07_18-47-18.png · 18 KB · click to show
the main file is in the root dir, so it would be like this: main.qml --- components --- commons
R
qmldir: module Character Character 1.0 Character.qml I tried adding the paths into my ENV and also creating a .qmlproject and that did not work as well.
B
I'm not sing the main.qml in your screenshot
B
And the file, you are trying to access is the qml file under commons is that right ?
B
according to this achitecture main.qml |—side/ | |—-common | |—-- Test.qml on your main.qml { import "side/common" Test { } }
Here import "components/commons" ApplicationWindow { id: page width: Screen.desktopAvailableWidth height: Screen.desktopAvailableHeight visible: true property var intel: Character function log() { console.log(page.intel.last_stat_value) console.debug(Character.character_) console.log(page.intel.nada) }
R
qml: undefined qml: undefined qml: undefined
B
I could not help if I can read the error line
R
Character.qml import QtQuick 2.12 Item { id: nada property var character_: { "id": 174 } property int last_stat_value: 0 property string last_stat: "" property var character_info: { "id": 174, "creation_type": "fast", "points_total": [6, 7, 4, 10, 10, 6, 8, 5, 6] } } (removed other values for brevity)
bayangcould you show it
19:03:55: Starting python -u main.py... ['/usr/bin', 'qrc:/qt-project.org/imports', '/home/chombatta/venv/lib/python3.8/site-packages/PySide2/Qt/qml'] qml: undefined qml: undefined qml: undefined
R
thats's all we have on the console.
Файл
image_2021-08-07_19-07-44.png · 28 KB · click to show
Using the Module Import:
R
then, obviously: QQmlApplicationEngine failed to load component file:///home/chombatta/chombatta-backend/main.qml:8:1: module "Character" is not installed 19:07:36: /home/chombatta/venv/bin/python exited with code 255
in the main.qml you should declare your Character as this ApplicationWindow { id: page width: Screen.desktopAvailableWidth height: Screen.desktopAvailableHeight visible: true //////////////////////////////////////// Character { id: intel } //////////////////////////////////////// function log() { console.log(page.intel.last_stat_value) console.debug(Character.character_) console.log(page.intel.nada) }
I was about to let you know when you sent de message. 😁😁
R
Ideally, I'd create a singleton (or something like that) instead of global variables. Then, I can work on in a more flexible manner.
B
The second one method, it is to have a global variable inside a unique qml file like ValueSource.qml, so that i could import it in any other file like we did and respecting the import rule.
B
The most important thing is to find your method flexible.
sure!! you just have to becareful when working with globals because they can add nasty bugs.
R
in any programming languages, actually.
K
So, I hadn't been doing much Qt for Python/PySide stuff, instead working with customers that have Qt C++ projects, but a few days back I started a hobby project to help my girlfriend. She wanted an automated way to count pills, and was asking if a particular app on the Amazon app store was ok, as it seemed sketchy to her. I agreed - it was asking for all sorts of permissions it shouldn't need like location permission. Anyway, she was wondering if I could make such an app. I could make something for Android, but it would take me some time, and I thought the project would be a good way to get some experience with using PySide6 with QML and opencv.
D
hey guys , maybe somebody can you tell me what its the wrong of my code , please :c this is the qml CustomButton { id: button x: 75 width: 150 height: 35 text: "CALCULAR" anchors.top: parent.top font.pointSize: 15 anchors.topMargin: 15 anchors.horizontalCenter: parent.horizontalCenter onClicked: { backend.multi(number1.text , number2.text) } } Connections{ target: backend function onSetMulti(result){ multiResult.text = result } and this is the python code setMulti = Signal(str) @Slot(str) #funciones def multi(self,n1,n2): result = float(n1)*float(n2) self.setMulti.emit(result)
So far I have a very minimal QML UI - and the pill counting logic is certainly far from done. I'm still understanding how to do the pill counting with opencv - so far been playing with HSV filters to make the pills in the image pop out in a binary bitmap. I've got a custom QQuickImageProvider that serves up the processed images from OpenCV for display while I figure out what thresholds I need, etc.. Where I'm stuck now is that I haven't been able to figure out how to get QML to re-fetch the image from the QQuickImageProvider. It's not really designed for updated images it seems, so I think I need to serve up the image as a QImage property exposed from Python, which I can then update and have QML see the updates, but I'm not sure.
D
this is the error : TypeError: numero1() missing 1 required positional argument: 'n2'
K
That way I can provide a rig with a controlled environment for the pill images.
D
i'm supposedly sending all the arguments but i don't know why the error
Camera pointed down, black matte surface, just dump pills on the surface in a box that defines what the camera sees, and hopefully I can automate it such that it will see that there's new contents on the plate, and just give a pill count. The display could be really dirt simple and no PySide heh - just 7 segment displays.
setMulti = Signal(str) @Slot(str) def multi(self,n1,n2): result = float(n1)*float(n2) self.setMulti.emit(result)
@Keithel on your image from OpenCV, are make some process on each frame before trying to parse it to qml ?
bayang@Keithel on your image from OpenCV, are make some process on each frame before trying to parse it to qml ?
I have a PillCounter class I @QmlElement-ize and instantiate from QML. That will load and process the image when an imagePath property is set in QML, and that in-turn will convert the image to a QImage and add it to a singleton CVImageProvider (derived from QQuickImageProvider) - which stores it in a dictionary from image path to QImage. When the image provider is requested to provide an image with the same id, it's just served up from the dictionary, resized if requested.
K
I kind of wanted it to be a practical example of how to use @QmlElement, Property, and Signal, allowing easy instantiation of Python types from QML.
D
thank you so much , I've been trying to do the backend and I got caught up in this :c
(you should be using Integers for numbers, so in your Qml do Number(the_number_your_are_passing).
R
Like so: myapp.multi(Number(n1), Number(n2))
Like this you could easily access python_type in QML
Фотография
click to show
B
Фотография
click to show
D
I am still learning how to connect qml with python and some things were not clear to me but I am already understanding, really thank you very much :D
Calendar: August 2021
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog