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. QML/C++ Design
Forum Updated to NodeBB v4.3 + New Features

QML/C++ Design

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 4 Posters 4.1k 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.
  • T Offline
    T Offline
    tbones
    wrote on last edited by
    #1

    We will have an application with many QML pages. What is the best design approach for navigating pages and sending data from C++ to the QML?

    One solution we've talked about is every time a new page is requested it comes back to the C++ code to have the qml loaded for instance using ->setSource(QUrl("qrc:/qml/Main.qml"));
    and then a user clicks and we do ->setSource(QUrl("qrc:/qml/Pag1.qml")); etc...

    Or is it better to let QML go from page to page using Loader and just setting all the attributes? into the context ahead of time like
    @
    context->setContextProperty("myClass", myClass);
    context->setContextProperty("myClass1", myClass1);
    context->setContextProperty("myClass2", myClass2);
    @

    Would it be appropriate to load all of the context objects at initialization?

    EDIT: please use the @-tags for your code. I added them. gerolf

    1 Reply Last reply
    0
    • N Offline
      N Offline
      ngocketit
      wrote on last edited by
      #2

      Navigating between pages using QML has some advantages:

      1. You can have a so-called "windows stack" that you can go back & forth between views without losing their states and don't have to recreate them.
      2. You can apply effects when transitioning between views.

      Using QDeclarativeView::setSource() to move between views you'll lose the state of the previous view and have to recreate it when coming back.

      For context properties, you can set them in advance when the application starts and only access/load the needed data at the right time.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        johnk
        wrote on last edited by
        #3

        Hello tbones,

        One architecture would be to keep the models in C++ and allow QML to deal with the UI including transitions between windows. "Here":http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#c-data-models is a link to combining C++ models with QML.

        -jk

        1 Reply Last reply
        0
        • L Offline
          L Offline
          L.MCH
          wrote on last edited by
          #4

          I recently developed a multiplatform application running on Windows 7 and Windows CE and faced the same issue.

          The best solution is to encapsulate all the "heavy/complex" stuff in QML Items coded in C++ (i.e. derived from QDeclarativeItem ) and eventually some models in C++ as johnk said.

          Keeping all the "high level UI logic" in QML you can refactorize it quicker than using C++,
          for example you can switch from using qml loader to load one page at a time
          to loading all the pages in memory at startup without touching a line of C++.

          "Reloading from C++" (i.e. QDeclarativeView::setSource() ) makes sense only when you need to purge all the previously allocated QML data to reclaim memory quickly or when for a reason or another you want to be sure the UI code and data of different pages is clearly separated (i.e. one set of pages is coded by you and the other by the final user for customizations and you want/need to keep 'em separated just in case the final user makes some modifications that may affect your stuff).

          Because of the Windows CE requirement (read: a lot less memory available in the Windows CE devices) in my application I added that option too, but exposed the interface to the "C++ loader" on the QML side to let the UI coders decide when they really had to use it and they prefer to avoid it.

          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