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. Calling another window from main window
Forum Updated to NodeBB v4.3 + New Features

Calling another window from main window

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.7k 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
    student76
    wrote on last edited by
    #1

    Hi, I looked in many examples including Qt examples but i couldn't find any example that calls another window from the main window with menu, toolbar, etc. I made minimal app but I'm in dilemma of what is the right approach. I have 2 qml files named mainform.qml and subform.qml both ApplicationWindow types. I created QQmlApplicationEngine i loaded both files with QQmlApplicationEngine::load() method. Now, if this is the right way (I succeded with this approach ) do I have to pass around pointer to only instance of QQmlApplicationEngine or do I have to declare multiple engines when I need subform (which didn't work for me , every form instantiated after first one was non responsive, you couldn't click buttons, tabview tabstack wasn't there, etc.) or as in qt quick control text editor example I call it from qml file with mySubForm.show(). I suppose this is extremely trivial and beginner question but give me headache for hours. Also is there any non trivial open source qt quick app to learn by reading the code. Thanks in advance.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Babalas
      wrote on last edited by
      #2

      I've done something where I can pass in a custom qml file to load that can include Window.
      @ Loader {
      id: scriptLoader

                  property var model
                  signal finished
      
                  anchors.fill: engine
                  visible: false
      
                  onFinished: {
                      project.scriptDone()
                      source = ""
                  }
      
                  Connections {
                      target: project
                      onScriptInvoked: {
                          scriptLoader.model = state
                          scriptLoader.source = script
                      }
                  }
      
                  // Make sure windows get closed
                  Connections {
                      target: window
                      onClosing: {
                          if(scriptLoader.item) {
                              scriptLoader.item.visible = false;
                          }
                      }
                  }
              }@
      

      Then for an example qml file
      @import QtQuick 2.1
      import QtQuick.Window 2.1
      import QtQuick.Controls 1.0

      Window {
      visible: true
      flags: Qt.Dialog

      onClosing: finished()
      
      property var kv: model.keyValue("string")
      Column {
          Text {
              text: kv.name + " " + kv.value 
          }
      
          Button {
              text: "Helloooo"
              onClicked: console.debug("Button clicked")
          }
      }
      

      }
      @

      Couple of points to note

      • I had problems getting the window to close when the application closed hence the bit of code in Connections
      • All the model and kv stuff in there you can ignore. I just copied exactly what I've got.

      Also for examples have you found the qtquickcontrols/examples folder? There are a few other scattered examples folders as well that I've found quite helpful.

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

        Thank you Babalas qml approach is my slimmer side but this is perfect chance to learn more :).Thanks again.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Babalas
          wrote on last edited by
          #4

          Glad to help. I've stumbled my way through so I'm not certain if it is the "best" way to do it but it works.

          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