April 20, 2012

artem.marchenko artem.marche..
Lab Rat
54 posts

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?

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

2 replies

April 20, 2012

GentooXativa GentooXativa
Lab Rat
122 posts

Try to expose it to QML with setContextProperty [qt-project.org]

 Signature 

Jose Vicente Giner Sanchez - Senior Mobile Developer

www.gigigo.com

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

April 20, 2012

artem.marchenko artem.marche..
Lab Rat
54 posts

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.

 
  ‹‹ Qt5 Windows can’t find QtQuick      [SOLVED]expose enum method to qml ››

You must log in to post a reply. Not a member yet? Register here!