Best approach to retrieve values from a QML Modal dialog
In my QT C++ application i call a QML ModalDialog with 2 buttons (OK/CANCEL), which displays correctly on screen and so, no problem there.
However i'm struggling to find a way to retrieve in my QT C++ application which button was pressed.
I'm unable to somehow "freeze" when i call the QML ModalDialog, to wait there until the user press OK Button or Cancel Button
What i see is that application calls the QML ModalDialog, and immediately exit that part and continue.
QMetaObject::invokeMethod can call a QML function and have a return value, but it just doesn't wait for the user press one of the buttons, it just exits immediately, so no use.
I want to use this QML ModalDialog in several places of my application (the QML modal
dialog can have different text passed from my QT C++ application), so i was looking to a generic solution for this.
Basically and generic speaking i'm looking for something like this:
C/C++
return_value = QML_Modal_Dialog(....)
Can someone point me in the right direction? Thanks
Re: Best approach to retrieve values from a QML Modal dialog
Not exactly "[I]return_value = QML_Modal_Dialog(....)[/I]", but you can emit a signal from your QML file and execute a c++ slot to continue your c++ processing.
Something like this:
C++:
[CODE]void yourClass::loadQml(){
QString file = "qml/Yes/something.qml";
QDeclarativeView *qmlView = new QDeclarativeView(this);
qmlView->setSource(QUrl::fromLocalFile(file));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(qmlView);
qmlView->setFocus();
[B] QObject* listView = qmlView->rootObject()->findChild<QObject *>("listView");
connect(listView,SIGNAL(accepted()),this,SLOT(accepted()));
connect(listView,SIGNAL(cancelled()),this,SLOT(cancelled()));[/B]}[/CODE]
QML:
[CODE] ListView {
id: MyListView
objectName: "listView"
...
signal accepted
signal cancelled
}
...
...
...
MouseArea {
anchors.fill: parent
...
onClicked: {
[B] // emit the signal
MyListView.accepted();[/B] }
}
...
MouseArea {
anchors.fill: parent
...
onClicked: {
[B] // emit the signal
MyListView.cancelled();[/B] }
}[/CODE]
Re: Best approach to retrieve values from a QML Modal dialog
Thanks, i'll take a look at this