Solved Open/show and close/hide popup by QML code
-
There is a
Q_PROPERTY
in my registered C++ class:// C++ Class Q_PROPERTY(bool inProgress READ inProgress WRITE setInProgress NOTIFY inProgressChanged)
... based on which I intend to show a QML popup:
Popup { id: popup visible: cppClass.inProgress // Bind visibility to C++ Q_PROPERTY }
But the pop doesn't show up. If change
visible
totrue
the popup is always shown of course.Tried so far
Tried to use signal/slot connections to open/show the popup, but doesn't work:
Popup { id: popup visible: false Connections { target: cppClass onInProgressChanged: { if (cppClass.inProgress) { console.log("open ...") // This text is logged correctly popup.visible = Qt.binding(function(){return true}) // popup is NOT shown popup.open() // popup is NOT opened } else { console.log("close ...") popup.visible = Qt.binding(function(){return false}) popup.close() } } } }
What am I missing?
-
Popup { id: popup visible: cppClass.onProgress // Bind visibility to C++ Q_PROPERTY }
You have a typo here (should be
inProgress
, notonProgress
).The code seems correct, it should work. Some suggestions:
- make sure you don't have that typo in actual code :-)
- perhaps
inProgress
is changed when some very heavy, CPU-blocking operation is ongoing? Then QML engine might not have time to show the GUI changes. Try settinginProgress
first, then starting the CPU-heavy operation after some time, or in a different thread - maybe you are setting
inProgress
tofalse
immediately after you set it totrue
(the operation completes very fast)? - make sure the
inProgressChanged
signal is being emitted
-
Popup { id: popup visible: cppClass.onProgress // Bind visibility to C++ Q_PROPERTY }
You have a typo here (should be
inProgress
, notonProgress
).The code seems correct, it should work. Some suggestions:
- make sure you don't have that typo in actual code :-)
- perhaps
inProgress
is changed when some very heavy, CPU-blocking operation is ongoing? Then QML engine might not have time to show the GUI changes. Try settinginProgress
first, then starting the CPU-heavy operation after some time, or in a different thread - maybe you are setting
inProgress
tofalse
immediately after you set it totrue
(the operation completes very fast)? - make sure the
inProgressChanged
signal is being emitted
-
@sierdzio Thanks! There is no typo in the actual code. I'm going to check the other suggested items.
-
@sierdzio The code worked by triggering C++ signals further away from CPU-blocking operation.