I want to create an object list model like in this example: http://doc.qt.io/qt-5/qtquick-models-objectlistmodel-example.html
To use it in QML I need to set the context property
ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
In the above example, this is done in the main.cpp, however, I would like to do this in the constructor of the class which defines the model. Is there a way to get the context in my class definition? If not, what is the best practice to set the context?
Edit: Some more context: I am doing a QQuickItem which should plot a line. This model I wanted to use to hold the properties of the ticks, namely pixel position and string label, therefore it does not need to be editable, and if the zoom changes all values will need to change. The ticks I then wanted to draw using a ListView with a custom delegate. Therefore, ideally I wanted to define my model inside the QQuickItem, which is then created in QML.
QObejct
s and aListView
for some ticks sounds like a gigantic waste of resources. – dtechQObject
s part. – dtechText
. This is different from say if you draw the text as a part of the plot, without instantiating a bunch of text elements for each label. – dtech