Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-6658

Creating qdeclarative-boostable QML project for Harmattan/N9 with Qt Creator, makes QmlAppilcationViewer::setContextProperty to fail.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • Qt Creator 2.3.1
    • Remote Linux
    • 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

      { target: nfcManager onTargetDetected: console.log("foo") }

      ...

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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            installerteam Installer Team
            zchydem Marko Mattila
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes