Accessing QML Properties when object is instantiated as a quickWidget through QtDesigner
-
I wrote a tumbler module in QML that is setting date/time fields that I would like to access in C++. Originally the project was written using .ui files in QtDesigner, so I incorporated the tumbler module as a quickWidget and set the source url. I tried using different approaches like signals/slots and Q_Properties, but have not found success. Any help would be greatly appreciated as I am relatively new to using Qt!
QML Properties to be accessed:
C++ File
Tumbler Module inserted into .ui file as a quickWidget
I am probably missing some important information, so let me know. Thanks!
-
The updateComponent is not directly declared in QQuickWidget, instead of it, QQuickWidget has a item called RootObject that represent the first item on your view.
Beyong that, you must think in hierarchy of your qml file.
- If the tumbler module is the root object of your widget as below than you can directly access it from rootObject.
- QQuickWidget
- Root Item
Item{ // Your properties and signals }
QObject *item = ui->quickWidget->rootObject(); QObject::connect(item, SIGNAL(updateComponent(QString)), this, SLOT(handleUpdateComponent(QString)));
- On the other hand, if your module is inside of another object than you may set
objectName
property and find it from rootObject
- QQuickWidget
- Root Item
- Inner Item
- Root Item
Item{ Item{ objectName: "InnerObject" // your properties and signals } }
QObject *item = quickWidget.rootObject()->findChild<QObject *>("InnerObject"); QObject::connect(item, SIGNAL(updateComponent(QString)), this, SLOT(handleUpdateComponent(QString)));
-
@KillerSmath Thanks for the reply! That makes more sense. My object is at root so I went with the first approach.
I got it working now, thanks for the help!