Including MessageDialog



  • HI,

    I am using Qt5.2, i have a user input QML screen in which the user will fill form and submit.

    On Submit, i want to do the validations using the javascript function and if there is any error then show it as a popup.

    Can anyone please give a sample of how i can trigger the MessageDialog from the javascript function.
    And also i am not able to create a MessageDialog component even after including
    import QtQuick 2.2
    import QtQuick.Dialogs 1.1

    Is there anything else i need to include?

    Thanks in advance



  • Hi , did you see the example code at http://qt-project.org/doc/qt-5/qml-qtquick-dialogs-messagedialog.html#details ?
    What did you try and why doesn't it work for you? The example looks fairly easy to implement I guess.

    You just need to modify the code a little if you want to open it from a JS function, do it like
    @
    import QtQuick 2.2
    import QtQuick.Dialogs 1.1

    MessageDialog {
    id: messageDialog
    title: "May I have your attention please"
    text: "It's so cool that you are using Qt Quick."
    onAccepted: {
    // whatever you wanna do
    }
    }

    // in your JS function
    messageDialog.open()
    @

    if you want you can of course create the MessageDialog dynamically, but this is the easy way :)
    If you need to create it dynamically you can use a Loader or Component in QML.



  • Thank you.

    Even though after including
    import QtQuick 2.2
    import QtQuick.Dialogs 1.1

    For MessageDialog it says Unknown component. Do i need to add any library reference for my QtQuick 2 project .pro file?



  • Hi, I just tested it myself, works like it should be with Qt 5.2.1, you don't need to add any special libraries or modules in the project file. My test code:
    @
    import QtQuick 2.2
    import QtQuick.Dialogs 1.1

    Rectangle {
    width: 300
    height: 300

    Component.onCompleted: messageDialog.open()
    
    MessageDialog {
        id: messageDialog
        title: "May I have your attention please"
        text: "It's so cool that you are using Qt Quick."
    }
    

    }
    @

    that is all.. be aware that QtQuick.Dialogs is a dynamic QML plugin, so if you deploy your app and don't run that code from Qt Creator you have to deploy the QtQuick.Dialogs plugin with your app, obviously. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.