Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Setting model from C++ does not work on Androd ...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 631 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DBoosalis
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBoosalis
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved