Qml in C++/Qt on Android not visible



  • Hello,

    I have the problem that the QML part of my file is not shown on Android device. It works fine on Windows 8.1 Desktop (Qt 5.3). But on Android it only flashes the QML part for a moment and than the box disappears. What did I wrong?

    • My QML file is a simple one and it is stored on the Resouce file:
      @
      import QtQuick 2.0

    Rectangle {
    id: rectangle
    color: "red"
    width: 200
    height: 100
    }
    @

    AND the resource file called "m.qrc":
    @
    <RCC>
    <qresource prefix="/">
    <file>main.qml</file>
    </qresource>
    </RCC>
    @

    • In mainwindow.cpp I have the code:
      @
      #include<QtQuick/QQuickView>
      #include "mainwindow.h"
      #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QQuickView *view = new QQuickView();
    
    QWidget *container = QWidget::createWindowContainer(view, this);
    
    container->setGeometry(5,25,300,130);
    
    view->setSource(QUrl("qrc:/main.qml"));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    • In the .pro file I have the code
      @
      QT += core gui
      TEMPLATE += app
      QT += quick
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = ContC2
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    CONFIG += mobility
    MOBILITY =

    OTHER_FILES +=
    main.qml

    RESOURCES +=
    m.qrc
    @

    [edit: added missing coding tags @ SGaist]



  • Which is the android device? What is the Kernel version?

    You can check Force rendering GPU, option in settings with Android.



  • Did you need the QWidgets ??
    Because, if you don't need them, it's better to use a QQuickView directly into main.cpp:
    @
    QQuickView viewer;
    viewer.setResizeMode( QQuickView::SizeRootObjectToView );
    viewer.setSource( QUrl("qrc:/main.qml") );
    viewer.show();

    return app.exec();
    @

    If you need QWidget, then do not use the createWindowContainer that it has been replaced by QQuickWidget:
    @
    QQuickWidget *view = new QQuickWidget;
    view->setGeometry(5,25,300,130);
    view->setSource(QUrl("qrc:/main.qml"));
    @




Log in to reply
 

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