⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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

  • 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?


    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

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

  • 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.

Log in to reply