我正在尝试使用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。这种与bug有关的问题也影响了“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();
}
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
我希望有人可以提出一些建议。
答案 0 :(得分:4)
当前版本中的文件calculator.pro显然是错误的。它应该看起来更像这样:
# 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()
创建新项目时,将自动生成文件qtquick2applicationviewer。因此,您需要将它包含在main.cpp中:
#include "qtquick2applicationviewer.h"
特别是关于消息“无法将QString分配给QQuickItem ”,它似乎是你的qml文件中的一些sintax或参数定义问题,因为你可能想看看{{3 }}
这应该是您遇到项目问题的原因。