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. Injecting an item into model coming from C++ or "translating" C++ model into another QML model
Forum Updated to NodeBB v4.3 + New Features

Injecting an item into model coming from C++ or "translating" C++ model into another QML model

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.9k 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.
  • A Offline
    A Offline
    artem.marchenko
    wrote on last edited by
    #1

    Hi All

    I've got a model coming from C++ (Inhertited from QAbstractListItemModel) that is basically a list of contact for an instant messenger.

    App's UI, however, is to include one more special contact representing the current user (it makes sense on our devices with extremely discouraged chrome elements such as extra headers, scrollbars, etc).

    I can certainly, modify the model on C++ side, yet.. this special item is really just about the UI representation and therefore it seems very logical to me to perform such a modification in QML side. Is there a way to somehow inject an item into a model coming from C++? Or maybe there is a way to apply some rules to C++ model and make a QML ListModel or something like that as a result?

    Or how would you do it?

    Cheers,
    Artem.

    P.S.
    In most of cases there are going to be just a few elements in the model so cloning of model if needed shouldn't effect performance and memory use much

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GentooXativa
      wrote on last edited by
      #2

      Try to expose it to QML with "setContextProperty":http://qt-project.org/doc/qt-4.8/qdeclarativecontext.html#setContextProperty

      Jose Vicente Giner Sanchez - Senior Mobile Developer

      www.gigigo.com

      C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
      T: +34 917431436

      1 Reply Last reply
      0
      • A Offline
        A Offline
        artem.marchenko
        wrote on last edited by
        #3

        My c++ model is exposed to QML, no problem (though not as a context property, but as a property of some C++/QML element).

        Thing is I want to have a 2nd model (or same one, but modified), that is to be very similar to the original one, yet have an extra element (and maybe a couple of other elements are to be hidden). I am asking for an advice on the best way to do 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