4

I am trying to run a simple button on QML Android with C++.

The program compile and build using QString/QQmlEngine. When I try to run it, it gives this message:

kernel/qcoreapplication.cpp:418 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)): 
WARNING: QApplication was not created in the main() thread.

Which apparently is normal as quoted here: QApplication In Non-Main Thread . Then it gives the message:

qrc:///calculator.qml:33 ((null)): 
qrc:///calculator.qml:33:15: Unable to assign [undefined] to QString

I read that it is an unconfirmed bug, as quoted here: Qt Project - QTMOBILITY-1735. Such kind of bug related problems also affects the "Stencil buffer support missing, expect rendering errors", as I am developing for Tablet. If this is really a related bug, which seems to be case, there is any possible way around it? There should be some kind of possible hack to work this out. Basically, this is blocking almost everything to run.

The code is simple and small, as I am using it as framework, which simply makes a button run on the target device. Here is the short program, that I am using to try to get things to start working.

main.cpp

#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlEngine>
int main(int argc, char *argv[])
{   QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine(QUrl("qrc:///calculator.qml"));
    return app.exec();
}

calculator.qml

import QtQuick 2.0
import QtSensors 5.0
import QtQuick.Controls 1.0
Rectangle {
    id: button
    property bool checked: false
    property alias text : buttonText.text
    Accessible.name: text
    Accessible.description: "This button does " + text
    Accessible.role: Accessible.Button
    function accessiblePressAction() {
        button.clicked()
    }
    signal clicked
    width: buttonText.width + 20
    height: 30
    gradient: Gradient {
        GradientStop {
            position: 0.00;
            color: "#b0c4de";
        }
    }
    radius: 5
    antialiasing: true    
    Text {
        id: buttonText
        text: parent.description
        anchors.centerIn: parent
        font.pixelSize: parent.height * .5
        style: Text.Sunken
        color: "white"
        styleColor: "black"
    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: parent.clicked()
    }
    Keys.onSpacePressed: clicked()
}

calculator.pro

QT += qml quick sensors svg xml
OTHER_FILES += \
    calculator.qml
RESOURCES += \
    calculator.qrc
SOURCES += \
    calculator.cpp

I hope someone could come along with some suggestion.

Community
  • 1
  • 1
Hatsune Oko
  • 206
  • 1
  • 8
  • 1
    Are you using an outdated mobility? Based on the bugreport you mentioned, it seems to have been fixed upstream. – László Papp Dec 26 '13 at 07:29
  • @Laszlo Papp - Thanks for asking. The device I am developing is running on Android 4.3. I also updated the bug issue in my question, as you can check, that I am quoting also the bug QTBUG-30528. – Hatsune Oko Dec 26 '13 at 07:51

1 Answers1

4

Your file calculator.pro in the current version is apparently wrong. It should instead look something more like that:

# Add more folders to ship with the application, here
folder_01.source = qml/calculator
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
QT += qml quick sensors svg xml
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

The file qtquick2applicationviewer will be generated automatically when you create a new project. So, you need to include it to your main.cpp:

#include "qtquick2applicationviewer.h"

Specifically about the message "Unable to assign QString to QQuickItem", it seems to be some sintax or parameter definition problem from your qml file, as you probably may want to have a look here.

That should be the reasons why you are having problems with your project.

Community
  • 1
  • 1
Tanya Kadam
  • 129
  • 4