Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
Qt Creator 2.3.1
-
None
-
OS X/Lion / QtSDK 1.1.3
Description
Exposing a C++ QObject to the QML side using Harmattan/QmlApplicationViewer::setContextProperty fails to expose the object when using boostable project.
Steps to reproduce and for the workaround
- Create a new Qt Quick project using the latest QtSDK
- Make sure to select Harmattan target and boostable options
- Expose any QObject based object to the QML side using the following way:
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
Q_INIT_RESOURCE(NfcWiz);
NFCManager manager;
viewer->rootContext()->setContextProperty("nfcManager", &manager);
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer->setMainQmlFile("qrc:///qml/qml/NfcWiz/main.qml");
viewer->showExpanded();
return app->exec();
}
- Try to use your exposed object in a QML e.g.
...
Connections
...
- This will display a reference error in a console.
- A workaround for the problem is to add a public method to QmlApplicationViewer, which returns root context from a private view object e.g.
QDeclarativeContext * foo() const
{
return d->view->rootContext();
}
The problem is that the addition is done to the generated code, which can be overwritten almost at any time so the fix should be done when generating the code by Qt Creator.