replacing dialog with "regular" display
-
Hi all -
I've been tasked with altering an app. Current behavior is, when a button is pressed on a particular page, to display a dialog with two buttons (run now and run later). If "run now" is selected, an action occurs; if "run later" is selected, another dialog with a calendar and clock appears for the user to set the desired run time.
The customer wants to eliminate dialogs, and simply show full screen pages. The current implementation is this:
var component = Qt.createComponent("start_now_or_later.qml") var nowOrLater = component.createObject(this) nowOrLater.accepted.connect(function () { if (nowOrLater.getStartNow()) { ...
So, first question would be, if I eliminate the dialog, what is the mechanism for connecting the buttons in start_now_or_later.qml to the function above? In fact, do I even need a function, or should I just eliminate that page and display the buttons here?
Thanks...
-
@fcarney not exactly. Accepted() is a signal provided by the QML Dialog type:
I'm wondering:
- what the non-dialog equivalent to this is, and
- if I should even be bothering with signals/slots if I'm going to eliminate the dialog.
Thanks...
-
Then what is in start_now_or_later.qml?
I create some of my own "dialogs" based upon Window. I use similar signals to control the lifetime of the Window.
@fcarney start_now_or_later.qml currently contains the definition of the dialog that I want to replace. If I change the Dialog to Rectangle, and try to run it without further changes, I get a warning at the accepted.connect:
[QT-warning][v-c6ae7a2][thr:12986]qrc:/qml/DelayedStart.qml(18): qrc:/qml/DelayedStart.qml:18: TypeError: Cannot call method 'connect' of undefined
Which makes sense, because I'm not supplying anything to signal a button push (I think). I need to know how to connect these buttons, now that they're not part of a Dialog.
-
Rectangle { id: rect signal accepted() // or put a param in there if required Button { onTriggered: { rect.accepted() } } }
@fcarney thanks for that. Currently, when the app runs, I get a warning:
unknown(0): QQmlComponent: Component is not ready
According to some other threads, this suggests the application can't find a file, but this used to work. Is there another cause of this warning?
Thanks...
-
@mzimmers said in replacing dialog with "regular" display:
createComponent
https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-a-component-dynamically
Look at the function in that section called: createSpriteObjects. It shows how to delay createObject call if component is not ready.
-
@mzimmers said in replacing dialog with "regular" display:
createComponent
https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-a-component-dynamically
Look at the function in that section called: createSpriteObjects. It shows how to delay createObject call if component is not ready.
@fcarney interesting. Here's the code that you mentioned:
var component; var sprite; function createSpriteObjects() { component = Qt.createComponent("Sprite.qml"); if (component.status == Component.Ready) finishCreation(); else component.statusChanged.connect(finishCreation); } function finishCreation() { if (component.status == Component.Ready) { sprite = component.createObject(appWindow, {x: 100, y: 100}); if (sprite == null) { // Error Handling console.log("Error creating object"); } } else if (component.status == Component.Error) { // Error Handling console.log("Error loading component:", component.errorString()); } }
This explains a lot, but I don't see the delay that you mention...or was I supposed to add that myself?
This is beginning to add up for me...thanks for the help.
-
@fcarney interesting. Here's the code that you mentioned:
var component; var sprite; function createSpriteObjects() { component = Qt.createComponent("Sprite.qml"); if (component.status == Component.Ready) finishCreation(); else component.statusChanged.connect(finishCreation); } function finishCreation() { if (component.status == Component.Ready) { sprite = component.createObject(appWindow, {x: 100, y: 100}); if (sprite == null) { // Error Handling console.log("Error creating object"); } } else if (component.status == Component.Error) { // Error Handling console.log("Error loading component:", component.errorString()); } }
This explains a lot, but I don't see the delay that you mention...or was I supposed to add that myself?
This is beginning to add up for me...thanks for the help.
-
@mzimmers If component is not ready it connect it to a signal. This delays the execution of createObject to when it is actually ready.