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. Implement functionality of multiple windows in same QML file?
Qt 6.11 is out! See what's new in the release blog

Implement functionality of multiple windows in same QML file?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 35.3k 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.
  • D Offline
    D Offline
    Dark_Net01
    wrote on last edited by
    #1

    Hello, this is my first post here :) So, In my Qt Quick(Qt v5.4 and QtQuick 2.4) project I have these five .qml

    1.MainForm.ui.qml - Which contains the main window of the application
    2.main.qml - Contains all the functionality implementations of objects of mainForm.ui.qml, such as onClicked events, calling c++ functions getting value from textInputs etc.

    Q: Is my current setup for implementing functionality correct? Or should I implement all these things in the same file??

    1. dialog1.qml - Contains some text inputs for some settings etc.
    2. dialog2.qml - For some lists and tables in my application.
    3. dialog3.qml - Also contains some objects for an c++ function.

    All these qml files are created and destroyed at different times, on different button clicks. I'm using this method to open a dialog

    @addMenuArea.onClicked: {
    Qt.createComponent("addMenuAppDialog.qml").createObject(rootWindow, {});
    }@

    and for destroying the dialog:

    @MouseArea{
    anchors.fill: parent
    onClicked: {
    dialogComponent.destroy()
    }
    }@

    Now currently these dialogs doesn't have any functionality, like the main window, I want to do implement it all in one file(main.qml) without any javascript if possible. I have no Idea on how to link all the dialogs and main.qml so I can add the functions in main.qml. Is there a way to link these files using Loader QML type?

    Thanks!

    1 Reply Last reply
    0
    • shavS Offline
      shavS Offline
      shav
      wrote on last edited by
      #2

      Hi,

      You can use Window element in you main.qml file, something like this:
      @
      import QtQuick 2.4
      import QtQuick.Controls 1.3
      import QtQuick.Window 2.2
      import QtQuick.Dialogs 1.2

      ApplicationWindow {
      title: qsTr("Hello World")
      width: 640
      height: 480
      visible: true

      menuBar: MenuBar {
          Menu {
              title: qsTr("&File")
              MenuItem {
                  text: qsTr("&Open")
                  onTriggered: {
                      dialog1.show();
                  }
              }
              MenuItem {
                  text: qsTr("E&xit")
                  onTriggered: Qt.quit();
              }
          }
      }
      
      Window {
          id: dialog1
          width: 400
          height: 500
      }
      

      }
      @

      But you must remember in this case all resources will load when main.qml will loaded. And this is not good for optimize application. I think you need to use dynamic load the windows in your application.

      Mac OS and iOS Developer

      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