November 14, 2011

moldovan.catalin moldovan.cat..
Lab Rat
4 posts

[solved] ReferenceError: Can’t find variable… on MeeGo Harmattan

 

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:

  1.     QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
  2.     GenApplicationManager *appManager = GenApplicationManager::instance();
  3.     appManager->initialize(viewer.data());
  4.     viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
  5.     qDebug() << "root context before setMainQmlFile: " << viewer->rootContext();
  6.     appManager->run();    << I set here the properties  
  7.     qDebug() << "[appModel]: " << viewer->rootContext()->contextProperty("appModel");
  8.     viewer->setMainQmlFile(QLatin1String("qml/cuteBoxQml/main.qml"));
  9.     viewer->showExpanded();
  10.     qDebug() << "root context after setMainQmlFile: " << viewer->rootContext();
  11.     qDebug() << "[appModel]: " << viewer->rootContext()->contextProperty("appModel");

In appManager->run() I set the context properties I need:

  1. void GenApplicationManager::run()
  2. {
  3.     qDebug() << "[GenApplicationManager::run] - set AppMgr and appModel context properties";
  4.     _qmlViewer->rootContext()->setContextProperty("AppMgr", this);
  5.     _qmlViewer->rootContext()->setContextProperty("appModel", _applicationModel);
  6.     _thumbnailManager = new GenThumbnailManager(_applicationModel);
  7.     _thumbnailManager->start();
  8. }

…and in QML I use it like this:

  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import "ui"
  4. PageStackWindow {
  5.     id: appWindow
  6.     function setInitialPage() {
  7.         if (appModel.userToken === "" || appModel.userSecret === "")
  8.             return Qt.resolvedUrl("ui/WelcomePage.qml")
  9.         else
  10.             return Qt.resolvedUrl("ui/MainPage.qml")
  11.     }
  12.     initialPage: setInitialPage()
  13.     platformStyle: PageStackWindowStyle {
  14.         background: Qt.resolvedUrl("resources/images/cute_background.png")
  15.         backgroundFillMode: Image.PreserveAspectCrop
  16.     }
  17. }

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

November 14, 2011

moldovan.catalin moldovan.cat..
Lab Rat
4 posts

I find out this is a known issue due to new Qt Quick application template for Meego here is the bug report [bugreports.qt.nokia.com]
This post [meegoharmattandev.blogspot.com] gives a workaround for this issue until a fix is officially released.

 
  ‹‹ translations in QML files      UI Designer for Qml ››

You must log in to post a reply. Not a member yet? Register here!