Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Including MessageDialog
Qt 6.12 LTS is out! See what's new in the release blog

Including MessageDialog

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ssudhindrarao
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ssudhindrarao
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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. :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved