【发布时间】:2013-12-22 22:00:11
【问题描述】:
我正在尝试使用 C++ 在 QML Android 上运行一个简单的按钮。
程序使用QString/QQmlEngine 编译和构建。当我尝试运行它时,它会给出以下消息:
kernel/qcoreapplication.cpp:418 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)):
WARNING: QApplication was not created in the main() thread.
这里引用的显然是正常的:QApplication In Non-Main Thread。然后它给出消息:
qrc:///calculator.qml:33 ((null)):
qrc:///calculator.qml:33:15: Unable to assign [undefined] to QString
我读到这是一个未经证实的错误,如下所示:Qt Project - QTMOBILITY-1735。当我为平板电脑开发时,这种与错误相关的问题也会影响“Stencil buffer support missing, expect rendering errors”。如果这确实是一个相关的错误,似乎是这样,有什么可能的解决方法吗?应该有某种可能的黑客来解决这个问题。基本上,这几乎阻止了一切运行。
代码简单而小巧,因为我将它用作框架,它只是让一个按钮在目标设备上运行。这是一个简短的程序,我用它来尝试让事情开始工作。
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();
}
计算器.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()
}
计算器.pro
QT += qml quick sensors svg xml
OTHER_FILES += \
calculator.qml
RESOURCES += \
calculator.qrc
SOURCES += \
calculator.cpp
我希望有人能提出一些建议。
【问题讨论】:
-
您是否使用过时的移动设备?根据您提到的错误报告,它似乎已在上游修复。
-
@Laszlo Papp - 感谢您的提问。我正在开发的设备在 Android 4.3 上运行。我还更新了我的问题中的错误问题,如您所见,我还引用了错误 QTBUG-30528。
标签: android c++ qt mobile android-ndk