Really? Why am I doing it on daily basis, then :O
Maybe because I’m passing QObject pointers as global properties. But I also don’t remember any problems in changing those properties after setting QML file source.
Well, from what I’ve read here, [qt-project.org] it would seem that you’re doing something different than adding properties to the global object. Although I’m a noob so that link may just pertain to javascript files only.
Just out of curiosity, what are you trying to do? Update an object you pass into QML?
I’m trying to use set context property after the source has been set:
viewer->setSource(QUrl("qrc:/QML/main.qml"));
viewer->setWindowFlags(Qt::WindowStaysOnTopHint);
viewer->setWindowFlags(Qt::FramelessWindowHint);
viewer->setRenderHint(QPainter::TextAntialiasing);
...
viewer->rootContext()->setContextProperty("worklistModel", &m_worklistListModel);
For example, suppose there’s some code that forms a model for a list view I want to use. Right before the application gets to a particular screen it creates this model. I want to use set context property and add this instance to the root context. However unless that property was already set before I get an assert in JSTypeInfo (or something similiar) saying that the global object is being modified.
The way around this was basically to create a bogus instance and use set context property before set source, then update it afterwards. That though feels kind of hackish:
viewer->rootContext()->setContextProperty("worklistModel", &bogus);
viewer->setSource(QUrl("qrc:/QML/main.qml"));
...
viewer->rootContext()->setContextProperty("worklistModel", &m_worklistListModel);
↧