[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";
    engine.rootContext()->setContextProperty("myModel", &myModel);
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    return app.exec();

    @Rectangle {
    id: buttonArea
    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,

  • Moderators


    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

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