[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();
    qDebug() << "root context before setMainQmlFile: " << viewer->rootContext();
    appManager->run(); << I set here the properties
    qDebug() << "[appModel]: " << viewer->rootContext()->contextProperty("appModel");
    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);

    ...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")
    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.

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.