Implement functionality of multiple windows in same QML file?

  • 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:

    anchors.fill: parent
    onClicked: {

    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?


  • 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: {
            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.

Log in to reply

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