Results 1 to 5 of 5

Thread: How to implement a modal dialog in QML and get it's return value?

  1. #1
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default How to implement a modal dialog in QML and get it's return value?

    All,
    In Qt C++ lib, we can use dialog's exec() function and check it's return code to know whether the dialgo is accepted or rejected. In this way, I can get user's information easily by these code:
    ret = dialog.exec();
    if(ret == QDialog::Accepted)
    {
    // update information and do something
    }

    But I can not find exec() in QML. I can find open() function of dialog in QML, but it do not wait until dialog closed, and I can not find when to update information from dialog. Can anyone tell me how to use the modal function in QML?

  2. #2
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: How to implement a modal dialog in QML and get it's return value?

    Bellow is my solution. Is there any better solution?
    Qt Code:
    1. Button {
    2. id: buttonAppendDeviceList
    3. text: qsTr("æ·»åŠ è®¾å¤‡")
    4.  
    5. property var addControler:AddControler{
    6. modality: Qt.WindowModal
    7. onAccepted: {
    8.  
    9. listControlerModel.append({"deviceID":modbusAddress,
    10. "type":controlerType,
    11. "firmwareType":contorlerTypeIndex,
    12. "serialNumber":"",
    13. "programEnabled":true,
    14. "colorCode":"black",
    15. "currentProgress":0});
    16.  
    17. }
    18. }
    19.  
    20. onClicked: {
    21. addControler.modality = Qt.WindowModal;
    22. addControler.open();
    23. console.log("addControler.open();");
    24. console.log("listControler.currentIndex: ",listControler.currentIndex);
    25. listControler.currentIndex = listControler.currentIndex + 1;
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to implement a modal dialog in QML and get it's return value?

    QtQuick/QML is a declarative environment. You cannot think of it in terms of an imperative language such as C++. Getting a modal dialog in QtQuick is easy (make your "dialog" visible and put a MouseArea underneath it that will catch all the mouse events to prevent them reaching other objects) but this has nothing to do with "waiting until dialog is closed". The latter means blocking control flow which doesn't make sense in QML. If you think you need that then first it means you are wrong, and then it means you have too much imperative code. Try specifying the effect you want to achieve and we'll try to help you reach it in a more declarative way.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to implement a modal dialog in QML and get it's return value?

    QtQuick Control's Dialog base can do modal dialogs.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: How to implement a modal dialog in QML and get it's return value?

    wysota and anda_skoa,
    thank you! I understand it now.

Similar Threads

  1. Get (custom) return value of modal dialog?
    By Terreox in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2012, 15:20
  2. modal dialog in mouseReleaseEvent
    By cresta in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 03:18
  3. Non-Modal about dialog?
    By N3wb in forum Qt Programming
    Replies: 1
    Last Post: 8th December 2010, 05:47
  4. Help! How to implement CHECK & RETURN in signal/slots
    By apollocheun in forum Qt Programming
    Replies: 4
    Last Post: 23rd July 2010, 09:51
  5. QT Modal Dialog
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2010, 17:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.