Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [solved] ReferenceError: Can't find variable... on MeeGo Harmattan

    QML and Qt Quick
    1
    2
    4172
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      moldovan.catalin last edited by

      I was wandering if any of you could help me with a problem I'm facing on Harmattan maybe you encountered this issue:
      I always get file:///opt/cuteBoxQml/qml/cuteBoxQml/main.qml:9: ReferenceError: Can't find variable: appModel, but works on Desktop (Windows 7)
      I have an application model class in C++ that I want to expose to QML rootContext so before setting my main QML file and I do something like this:

      @ QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
      GenApplicationManager *appManager = GenApplicationManager::instance();
      appManager->initialize(viewer.data());
      viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
      qDebug() << "root context before setMainQmlFile: " << viewer->rootContext();
      appManager->run(); << I set here the properties
      qDebug() << "[appModel]: " << viewer->rootContext()->contextProperty("appModel");
      viewer->setMainQmlFile(QLatin1String("qml/cuteBoxQml/main.qml"));
      viewer->showExpanded();
      qDebug() << "root context after setMainQmlFile: " << viewer->rootContext();
      qDebug() << "[appModel]: " << viewer->rootContext()->contextProperty("appModel");
      @
      In appManager->run() I set the context properties I need:

      @void GenApplicationManager::run()
      {
      qDebug() << "[GenApplicationManager::run] - set AppMgr and appModel context properties";
      _qmlViewer->rootContext()->setContextProperty("AppMgr", this);
      _qmlViewer->rootContext()->setContextProperty("appModel", _applicationModel);
      _thumbnailManager = new GenThumbnailManager(_applicationModel);
      _thumbnailManager->start();
      }@

      ...and in QML I use it like this:

      @import QtQuick 1.1
      import com.nokia.meego 1.0
      import "ui"
      PageStackWindow {
      id: appWindow
      function setInitialPage() {
      if (appModel.userToken === "" || appModel.userSecret === "")
      return Qt.resolvedUrl("ui/WelcomePage.qml")
      else
      return Qt.resolvedUrl("ui/MainPage.qml")
      }
      initialPage: setInitialPage()
      platformStyle: PageStackWindowStyle {
      background: Qt.resolvedUrl("resources/images/cute_background.png")
      backgroundFillMode: Image.PreserveAspectCrop
      }
      }@

      I used same code on Desktop (Windows 7) and MeeGo (N9), it works on Desktop flawlessly but on N9 fails with that ReferenceError.
      Any help would be appreciated.

      1 Reply Last reply Reply Quote 0
      • M
        moldovan.catalin last edited by

        I find out this is a known issue due to new Qt Quick application template for Meego here is the "bug report":https://bugreports.qt.nokia.com/browse/QTCREATORBUG-6490
        This "post":http://meegoharmattandev.blogspot.com/2011/11/qmlapplicationviewer-and.html gives a workaround for this issue until a fix is officially released.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post