Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Setting model from C++ does not work on Androd ...



  • ... but it does work on Desktop

    Ok, I am using Qt 5.4.1 (the latest) If I try to set a string list model from C++ it fails on actual Android device (Nexus 5), The screen is just black. However the same code runs fine on my Ubuntu Desktop.

    Here is my code:
    @int main(int argc, char *argv[])
    {
    QStringListModel myModel;
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    QStringList list;
    list << "one" << "two" << "three" << "four";
    myModel.setStringList(list);
    engine.rootContext()->setContextProperty("myModel", &myModel);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    window->show();
    return app.exec();
    }
    @

    main.qml
    ...
    @Rectangle {
    id: buttonArea
    color:"red"
    anchors.fill: parent
    GridView {
    width: 300; height: 200
    cellHeight: 100
    cellWidth: 100
    id: gView;
    model: myModel;
    delegate: buttonDelegate
    anchors.fill: parent
    }
    }
    ...
    }@

    Any idea as to why this fails on Andoid ?

    Thank for any help here,
    David


  • Moderators

    Hi,

    AFAIK, Android doesnot support multiple windows. Any reason you are casting it to QQuickWindow ? QQmlAppEngine is in anyway going to load and display it.



  • Thank your for fixing the problem. That was just ignorance on my part


Log in to reply