Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]Best way to create a QML Dialog with QQuickView, to be run before main QML window
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Best way to create a QML Dialog with QQuickView, to be run before main QML window

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.9k 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.
  • T Offline
    T Offline
    Tory Gaurnier
    wrote on last edited by
    #1

    OK, so what I am doing is I have a QQuickView set to a 'main.qml' file, which is my main app window, then I have QGuiApplication, now I've come to realize that as soon as QGuiApplication::exec() is called my main.qml file is run along with all it's javascript, even if I don't call QQuickView::show(), what I need is the best way to create a QML dialog that will show before my main.qml, and before any of it's javascript is executed, I was thinking of having another QGuiApplication just for my dialog, which would then force everything else to wait until it's destroyed, but that doesn't seem like a very elegant way of handling this. What's the best way of creating a "pre-run" dialog in QML with Qt Quick???

    This is going to be a "first run" dialog, to set up app configurations when the app is run for the first time. Please let me know if my question doesn't make sense and I'll try to clarify.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      portoist
      wrote on last edited by
      #2

      You can split your Dialog and App into two .qml files and have something like this maybe:
      File Dialog.qml:
      @
      import QtQtuick 2.0
      Rectangle{
      signal done()
      Text{
      anchors.centerIn: parent
      text: "This is my dialog"
      }
      MouseArea{
      anchors.centerIn: parent
      onClicked: parent.done()
      }
      }
      @
      File MyApp.qml:
      @
      import QtQtuick 2.0
      Rectangle{
      Text{
      anchors.centerIn: parent
      text: "This is my app"
      }
      }
      @
      and main.qml:
      @
      import QtQtuick 2.0

      Rectangle{
      width: 640
      height: 480

      Dialog{
      id: dialog
      anchors.fill: parent
      onDone: {
      dialog.visible = false;
      }
      }

      MyApp{
      id: app
      anchors.fill: parent
      visible: !dialog.visible
      }

      }

      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tory Gaurnier
        wrote on last edited by
        #3

        Interesting, I'm very new to QML, and it seems I'm learning new things about it every day, I never realized I could use a component I created just by calling it in QML (MyComponent.qml then in a QML file use MyComponent{}), and I didn't really think to make my own signal, one of the issues was I was relying on Component.onCompleted for a lot of my Javascript, which is why main.qml's Javascript was running even when it wasn't being shown.

        So, I'm getting ideas now, using the example you posted above, could I do something like this?:
        @
        MyApp {
        id: app
        dialog.onDone: {
        //Javascript goes here
        }
        }
        @

        Or for a reverse, something like this?:
        @
        MyApp {
        id: app
        signal ready()
        onReady(): {
        //Javascript here
        }
        }
        Dialog {
        id: dialog
        MouseArea {
        anchors.centerIn: parent
        onClicked: app.ready()
        }
        }
        @

        Does that look like it would work?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          portoist
          wrote on last edited by
          #4

          MyApp in first example that you've posted, doesn't know what dialog is. You can pass dialog as property and connect to its signal using Connections:
          @
          MyApp {
          id: app
          property Dialog dialog
          Connections{
          target: dialog
          onDone: {
          console.log("done")
          }
          }
          }
          @
          In second example, when adding handler to signal, dont use "()", right syntax is:
          @
          MyApp {
          id: app
          signal ready()
          onReady: {
          //Javascript here
          }
          }
          @
          I suggest you to go through examples that can be found in Qt SDK, you can find a lot from them.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tory Gaurnier
            wrote on last edited by
            #5

            Ok, cool, this is putting me in the right direction, thanks for the help. And that was actually a typo when I added the '()' on the 'onReady', I already knew about that syntax :P But I wouldn't have thought about passing the dialog as a property.

            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 Extensions
            • Unsolved