×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    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

  2. #2
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: Best approach to retrieve values from a QML Modal dialog

    Not exactly "return_value = QML_Modal_Dialog(....)", 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();
        QObject* listView = qmlView->rootObject()->findChild<QObject *>("listView");
        connect(listView,SIGNAL(accepted()),this,SLOT(accepted()));
        connect(listView,SIGNAL(cancelled()),this,SLOT(cancelled()));}
    QML:

    Code:
                ListView {
                    id: MyListView
                    objectName: "listView"
                    ...
                    signal accepted
                    signal cancelled
                 }
    
                    ...
                    ...
                    ...
    
                    MouseArea {
                        anchors.fill: parent
                         ...
                        onClicked: {
                            // emit the signal
                            MyListView.accepted();                    }
                    }
                    ...
    
                    MouseArea {
                        anchors.fill: parent
                         ...
                        onClicked: {
                            // emit the signal
                            MyListView.cancelled();                    }
                    }
    -CarlosDL

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    2

    Re: Best approach to retrieve values from a QML Modal dialog

    Thanks, i'll take a look at this
    Last edited by _MrData_; 2011-05-03 at 19:21. Reason: wrong forum answer/unable to delete post

Similar Threads

  1. How to call/load another QML file from QML ?
    By cadlg in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-07-28, 09:15
  2. How to retrieve vars from QML components
    By KevinSharp in forum [Archived] Qt Quick
    Replies: 4
    Last Post: 2011-01-25, 16:58
  3. retrieve values from RArray
    By remyag in forum Symbian
    Replies: 7
    Last Post: 2009-08-05, 07:55
  4. Modal Dialog key events causing dialog to exit
    By roland.berry in forum Symbian
    Replies: 0
    Last Post: 2007-07-19, 10:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×