Wait for dialog response
-
To Quick Controls 2 I'm rather convinced, with this single exception... :-)
But really, You opened my eyes for some facts about those dialogs. I have to digest that and weigh what will be more suitable for my app.
So I'm quite satisfied with Your answers.
Thank You a lot. -
Hi,
What kind of dialog do you want to call ?
-
Any...
let's sayDialog
of QML.To be precise, I have many places when C++ routines called
QMessageBox
or customQDialog
.
So it is head-breaking how to split every of those functions and do not spoil the logic that just works.
So if there is any way how to ie.:- from a place where dialog was called, send a signal for a dialog
- then freeze C++ there by some mutex
- respond for a signal and perform a dialog on QML side
- get returned value and unlock the mutex
- continue C++ routine with returned value
But I'm not sure is it possible or wise and maybe there is easiest way to do it,
so any clue is appreciated -
Can you show an example of such a code path ?
-
void someMethod(int param) { int var1, var2; // some preparation for dialog... // C++ way to display a dialog and wait for response auto myDialog = new MySummaryDialog(param); int returnValue = mySummaryDialog::exec(); // possible QML way: emit getSummaryDialog(param); // HOW TO lock code here until QML dialog close // continuation of someMethod() routines, depends on many variables declared inside // a few combinations of: if (returnValue == var1) { // ... } else if (returnValue == var2) { // ... } // else etc... }
-
@Pablo-J.-Rogina
Thanks for response.Unfortunately all QML dialogues (either
Dialog
orMessageBox
) exists in parallel with code that invoked it.Dialog { id: someDialog } function callDialog() { someDialog.open() // I would expect here to know what user did to the dialog but it is not a case of QML (declarative programming) }
So I'm asking is it possible to bend this situation?
-
@SeeLook I was able to modify DialogPage.qml from this example I mentioned and by adding a Label at the top level (just after existing Label) I can display what the user input after closing "Input" dialog that pops up when clicking "Input" button in the example...
... text: "Dialog is a popup that is mostly used for short-term tasks " + "and brief communications with the user." } Label { id: result width: parent.width wrapMode: Label.Wrap horizontalAlignment: Qt.AlignHCenter } Button { text: "Message" ... Dialog { id: inputDialog ... standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { result.text = "user: " + user.text + " password: " + password.text } ... ... TextField { id: user focus: true placeholderText: "Username" Layout.fillWidth: true } TextField { id: password placeholderText: "Password" echoMode: TextField.PasswordEchoOnEdit Layout.fillWidth: true } ...
-
@mrjj , @Pablo-J-Rogina
Thank You for the clue.
ButDialog
of Qt Quick 2 (which hasmodal
property) is rather like a popup - it has no any titlebar and frame. I'm using that one fromimport QtQuick.Dialogs 1.3
.
However I will reconsider it.
This dialog business is messy for me.... -
-
To Quick Controls 2 I'm rather convinced, with this single exception... :-)
But really, You opened my eyes for some facts about those dialogs. I have to digest that and weigh what will be more suitable for my app.
So I'm quite satisfied with Your answers.
Thank You a lot. -
Hi, Yes it's possible. You can pass your dialog by context in the main.cpp file like that:
ResetDialog* resetDialog = new ResetDialog(); engine.rootContext()->setContextProperty("resetDialog", resetDialog);
and catch the result like that in the qml file:
Connections{target: resetDialog; onAccepted: {console.log("I WAS ACCEPTED"); onRejected: {console.log("I was Rejected")}}}