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. MVVM / MVP and QML
QtWS25 Last Chance

MVVM / MVP and QML

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

    Hi!

    I am comletely new to phone development, but watching a few videos, tutorials, and knowing a great deal of C++, I have come to the conclusion suggested by others, that the best approach to cross-platform development, is to try to write the application logic once, and then write the UI multiple times for each platform.

    Making friends with XAML for WP8 further strengthened this opinion of mine. Creating UI with Visual Studio Blend is extremely fast, and editing the generated XAML file is as easy as it can get. Wonderful tools, really. The entire VS+Blend+XAML is designed around the pattern MVVM. It seems to me as if Qt would be goind something very similar.

    XAML >> QML
    INotifyProperty >> Q_PROPERTY
    Delegates/Commands >> Signal/Slot

    • Are my assumptions right, that the very same MVVM pattern could be implemented using QML?

    Unfortunately, the MVVM pattern uses the Model solely to store data, and most of the application logic is inside the ViewModel, plus Views yet again are platformspecific. I wanted to put most, if not all of my logic into the Model, that would be completely portable, as it would be pure C++11. The ViewModel would only mediate between the View and the Model, converting the data (or simply exposing it) using platform specific machinery. In WinRT case, that would be XAML and it's data binding, and in Qt's case it would be it's own data binding mechanism. Some logic (mostly 3D) that is dependant on the type of View even at the Model level naturally have to be elevated to the ViewModel level, in which case it would do actual work. Other than these performance-critical sections, ViewModel need not do anything, than relaying the Model data.

    • Is this MVVM at all? Does this make sense in terms of Qt? (and in terms of WinRT?)

    I do not believe in me being able to rapidly prototype an Android, WP8 type interface quickly. I would like to idea of having to use only a single tool and get natively looking UI on all platforms, and Qt has proven it's capabilities on the desktop, but I have doubts about WP8.

    • Can QML create WP8 UI that translates to something looking completely identical to the built-in HUB, etc. WinRT Views?
    1 Reply Last reply
    0
    • T Offline
      T Offline
      tbochtl
      wrote on last edited by
      #2

      Hi,

      I got the exact same feeling that Qt/QML and .NET/WPF cover the same pattern and that MVVM could be implemented in Qt/QML as well. I found an example on the web, that tries to give an example of how to do this:

      https://bitbucket.org/AntyaDev/qtquickmvvmexample

      Also, there was a talk on the Qt Dev Days 2013 about a related topic:

      https://www.qtdeveloperdays.com/2013/northamerica/2013/c-object-adapter-layer-qml

      However, I am as well pretty new to QML and cannot tell you anything from real live experiences. So I would be really interested in the opion of the community, too.

      1 Reply Last reply
      0
      • GTDevG Offline
        GTDevG Offline
        GTDev
        wrote on last edited by
        #3

        With Qt there are QML and C++ as different languages, with basic principles that span over both worlds. It can be a bit confusing how to best structure your app.

        Apart from Qt's built-in Model-View system, it makes sense to introduce an MVC-like architecture.

        For this purpose, we've prepared a guide how to best structure QML-driven apps, and when to use C++ vs. QML. See the full guide here: https://v-play.net/apps/avoid-cpp-models-qt

        Best,
        GTDev

        Senior Developer at Felgo - https://felgo.com/qt

        Develop mobile Apps for iOS & Android with Qt
        Felgo is an official Qt Technology Partner

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

          I do found Qml to be more MVU, where your model the frontier between the Qml and C++. Qml/C++ update the model and the view adjust to the changed events. I would not force those view model too much, Qml can convert or cherry pick the information out of the model pretty easily. The only times I need view models is when I have long list of objects and I need to sort/filter. Make the C++ view model make sense at that point.

          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