Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qml in C++/Qt on Android not visible
Forum Updated to NodeBB v4.3 + New Features

Qml in C++/Qt on Android not visible

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 4 Posters 1.9k 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.
  • F Offline
    F Offline
    Flavia
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcm_qt
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • GianlucaG Offline
        GianlucaG Offline
        Gianluca
        wrote on last edited by
        #3

        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"));
        @

        1 Reply Last reply
        0
        • metaDomM Offline
          metaDomM Offline
          metaDom
          wrote on last edited by
          #4

          check this bug:

          https://bugreports.qt-project.org/browse/QTBUG-41467

          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