Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dynamically loading and unloading a QML file
Forum Updated to NodeBB v4.3 + New Features

Dynamically loading and unloading a QML file

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.4k 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.
  • P Offline
    P Offline
    prasadk
    wrote on 30 Jul 2013, 02:02 last edited by
    #1

    Hi ,
    In my Qt code I am loading a QML file like this m_view->setSource(QUrl("qrc:///main.qml"));
    *main.qml is my main view. On the click of a button I need to reset the source and load a new QML file
    something like m_view->setSource(QUrl("qrc:///numbers.qml")); which will have different QML components.
    is there a way where I can unload the previous QML file and load the new one. Due to some design constraints I can have only one view at a time.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 30 Jul 2013, 05:51 last edited by
      #2

      Use Loader element in QML. If you want to do it as you describe, you probably need to close the window, delete your QQuickView and then set it up again from scratch. IMO, Loader is much better here.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        monsingh
        wrote on 30 Jul 2013, 06:02 last edited by
        #3

        Hi

        this is applicable for qml in QT ie; qml is incorparated with Qt;

        you can subclassing QDeclarativeView api in your class.

        Class1

        setSource(QUrl("qrc:/qml/Main.qml"));

        Class2

        setSource(QUrl("qrc:/qml/Sub.qml"));

        based on the event change, you can change the qml dynamically.

        this will works

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prasadk
          wrote on 30 Jul 2013, 15:56 last edited by
          #4

          Hi monsingh,
          Is there a way to unload the previously loaded view ? Some thing like this
          m_view->resetSource()
          So that I can unload the previously loaded qml file and load the new one.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            prasadk
            wrote on 30 Jul 2013, 15:57 last edited by
            #5

            Hi sierdzio,
            If I am use the loader still there will be 2 views at a time. Unfortunately I can have only one view at a time .

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 31 Jul 2013, 05:34 last edited by
              #6

              No. Open a single QML file that contains only the loader element. Then you load your main.qml there. When you need to switch, you change the source of the Loader to numbers.qml and you're all set. Single window.

              (Z(:^

              1 Reply Last reply
              0

              1/6

              30 Jul 2013, 02:02

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved