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.
7 August 2021
RicardoHi, 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 (
Hi
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.
RicardoHi, 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 (
hope that, this could help you :)
bayanghope that, this could help you :)
Thank you! I will have a look on it tomorrow. Seems quite easy with your approach.
RicardoI tried @bayangp0 suggestions, but I still got "undefined" when accessing the property I want.
You are trying accessing the from which qml file?
Ссылка
click to show
click to show
as a matter of reference, this is a similar situation:
https://forum.qt.io/topic/87096/what-is-the-best-way-to-declare-a-global-variable-in-qml
I follow the link suggested on the reply:
https://doc.qt.io/qt-5/qtqml-modules-qmldir.html
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)
}
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
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)
}
@rcpp85 does it worked ?
bayanghow about global variable in QML
That's how I reached to this point: trying to see how to declare a global variable the best way possible.
RicardoThat's how I reached to this point: trying to see how to declare a global variable the best way possible.
I usually declare a property in the top level (main.qml) so that i can reach it in any file,
At each inheritance level I declare a variable which will transfer the variable from the parent to the next child, and so on.
Ricardosure!! you just have to becareful when working with globals because they can add nasty bugs.
Yeah, these global value stuck me many time, something as for a long week to solve the issue
RicardoIdeally, I'd create a singleton (or something like that) instead of global variables. Then, I can work on in a more flexible manner.
You're aware of registerSingletonType ? (I don't recall the exact name, but it's a call you can make on the engine to register a type - I think it's available in the python API). This will register a singleton object that the engine will instantiate.
Keith KyzivatYou're aware of registerSingletonType ? (I don't recall the exact name, but it's a call you can make on the engine to register a type - I think it's available in the python API). This will register a singleton object that the engine will instantiate.
yeah, I assume it. This could work too.
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.
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.
Keith KyzivatSo, 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 i
PySide6 can run on android? If so, it is waouh.
bayangPySide6 can run on android? If so, it is waouh.
Nono. I'm going to provide them a Raspberry Pi with pi camera I think.
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.
Dthis is the error : TypeError: numero1() missing
1 required positional argument: 'n2'
In the code you pasted, I don't see a numero1 function defined. Why don't you paste more of your project into a pastebin site and post a link for us to look at.
bayang@Keithel on your image from OpenCV, are make some process on each frame before trying to parse it to qml ?
sorry for that question, I forget that you filter image
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.
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.
Ссылка
click to show
click to show
sorry :'c , in this case
this is my python code and..:
https://pastebin.com/AhCLrP6Y
this is my qml code :
https://pastebin.com/HBfJ6cX6
Dsorry :'c , in this case
this is my python code and..:
https://pastebin.com/AhCLrP6Y
this is my qml code :
https://pastebin.com/HBfJ6cX6
Driving in a few minutes, but I'll take a look when I get a chance.
Keith KyzivatNono. I'm going to provide them a Raspberry Pi with pi camera I think.
Ow!! What kind of pills count is this?? Does these programs work like that? I'm intrigued!! 😁😁
DsetMulti = Signal(str)
@Slot(str)
def multi(self,n1,n2):
result = float(n1)*float(n2)
self.setMulti.emit(result)
Your Slot have 1 argument, your function 2.
Try something like this:
@Slot(str, str)
Keith KyzivatI 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.
I think, using Worker could be a fast way to instatiate Python Type in QML, it could be using a QObject class with some @slot(PYTHON_type, result=QML_type).
RicardoOw!! What kind of pills count is this?? Does these programs work like that? I'm intrigued!! 😁😁
True! , thanks now it works fine.