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. Multi-page QML application
Forum Updated to NodeBB v4.3 + New Features

Multi-page QML application

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 3.7k Views
  • 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.
  • J Offline
    J Offline
    jars121
    wrote on last edited by
    #1

    G'day,

    I'm looking to develop a multi-page application utilising many discrete .qml files. Each .qml file represents a different page (e.g. settings page, help page, etc.). The user can set a default page to be loaded on application start, so there isn't a 'main.qml' equivalent. Below is a simplistic representation of what I'm trying to accomplish. From the image, any of the QML files (QML 1 through QML 5) can be shown on application start, with each having its own set of configuration files. Once in a page, the user can navigate to any of the other .qml pages. The pages DO NOT have to be loaded into memory on application start, they can be instantiated during runtime.

    0_1564558786640_Capture.PNG

    As for the startup functionality, I have a preference parameter which saves the user's preference for their startup page. In main.cpp, I then specify which page is loaded into the QQmlApplicationEngine as follows (number of available QML files reduced to 2 for simplicity in the example code):

    //Main.cpp
    QQmlApplicationEngine engine;
    
    preferencesFile *preferencesFilePointer = preferencesFile::getInstance();
    
    if (preferencesFilePointer->startupQML() == "QML 1"){
        engine.load(QUrl(QStringLiteral("qrc:/QML1.qml")));
    } else {
        engine.load(QUrl(QStringLiteral("qrc:/QML2.qml")));
    }
    

    The above code works as expected; if the user has saved QML1.qml as their startup preference, the QML1.qml file is presented. What I'm now trying to understand is the following:

    1. Is the above a reasonable approach?
    2. If the answer to 1 above is yes, would Loaders be the optimal/preferred mechanism by which I can switch between QML files in runtime?

    I'm sure I'll have follow up questions, but some guidance on the above 2 would be greatly appreciated for now!

    ODБOïO 1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      @jars121 said in Multi-page QML application:

      Is the above a reasonable approach?

      Yep, it looks fine, why not?

      If the answer to 1 above is yes, would Loaders be the optimal/preferred mechanism by which I can switch between QML files in runtime?

      Loaders are fine too. You also may look into StackView or even go in dynamic object creation by hands.

      1 Reply Last reply
      0
      • J jars121

        G'day,

        I'm looking to develop a multi-page application utilising many discrete .qml files. Each .qml file represents a different page (e.g. settings page, help page, etc.). The user can set a default page to be loaded on application start, so there isn't a 'main.qml' equivalent. Below is a simplistic representation of what I'm trying to accomplish. From the image, any of the QML files (QML 1 through QML 5) can be shown on application start, with each having its own set of configuration files. Once in a page, the user can navigate to any of the other .qml pages. The pages DO NOT have to be loaded into memory on application start, they can be instantiated during runtime.

        0_1564558786640_Capture.PNG

        As for the startup functionality, I have a preference parameter which saves the user's preference for their startup page. In main.cpp, I then specify which page is loaded into the QQmlApplicationEngine as follows (number of available QML files reduced to 2 for simplicity in the example code):

        //Main.cpp
        QQmlApplicationEngine engine;
        
        preferencesFile *preferencesFilePointer = preferencesFile::getInstance();
        
        if (preferencesFilePointer->startupQML() == "QML 1"){
            engine.load(QUrl(QStringLiteral("qrc:/QML1.qml")));
        } else {
            engine.load(QUrl(QStringLiteral("qrc:/QML2.qml")));
        }
        

        The above code works as expected; if the user has saved QML1.qml as their startup preference, the QML1.qml file is presented. What I'm now trying to understand is the following:

        1. Is the above a reasonable approach?
        2. If the answer to 1 above is yes, would Loaders be the optimal/preferred mechanism by which I can switch between QML files in runtime?

        I'm sure I'll have follow up questions, but some guidance on the above 2 would be greatly appreciated for now!

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #3

        hi

        I wonder how you do this, is the root component of all QMLs (1,2,3.. ) a QML ApplicationWindow or QML Window ?

        @jars121 said in Multi-page QML application:

        Is the above a reasonable approach?

        a simpler approach is to actually have a main.qml and have a Loader in it to load the page + Settings to save your prefered page

        //main.qml
        ApplicationWindow {
        property string initialPage : "QML1"

        Settings {
            property alias firstPage : initialPage  
        }
        

        Loader{
        // set the first page
        }

        }

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jars121
          wrote on last edited by
          #4

          Thank you both for your input.

          @LeLev each QML is based on a Window architecture.

          I gave this some further thought over night, and I tend to agree that using a main.qml is still probably the best approach. I'll eventually look to incorporate a SwipeView for movement between these various pages, so having a main.qml act as a loading page/container would be ideal.

          I'll have a play with this approach today and post back with any issues.

          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