[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:
- 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->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 === "")
- else
- }
- initialPage: setInitialPage()
- platformStyle: PageStackWindowStyle {
- 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
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.
You must log in to post a reply. Not a member yet? Register here!

