解决QString移动错误
Work around for QString mobile bug
我正试图用C++在QML Android上运行一个简单的按钮。
该程序使用QString/QQmlEngine进行编译和构建。当我尝试运行它时,它会给出以下信息:
kernel/qcoreapplication.cpp:418 (QCoreApplicationPrivate::QCoreApplicationPrivate(int&, char**, uint)):
WARNING: QApplication was not created in the main() thread.
这显然是正常的,正如这里引用的:非主线程中的QApplication。然后它给出一个信息:
qrc:///calculator.qml:33 ((null)):
qrc:///calculator.qml:33:15: Unable to assign [undefined] to QString
我读到这是一个未经证实的错误,引用如下:Qt项目-QTMOBILITY-1735。这种与bug相关的问题也会影响"模板缓冲区支持丢失,预计会出现渲染错误",因为我正在为Tablet开发。如果这真的是一个相关的bug,似乎是这样,有什么可能的方法来解决它吗?应该有某种可能的破解方法来解决这个问题。基本上,这几乎阻止了所有的运行。
代码简单小巧,因为我使用它作为框架,它只需在目标设备上运行一个按钮。这是一个短程序,我用它来尝试让事情开始运转。
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
我希望有人能提出一些建议。
当前版本中的文件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。因此,您需要将其包含在您的主程序中。cpp:
#include "qtquick2applicationviewer.h"
特别是关于消息">无法将QString分配给QQuickItem",这似乎是qml文件中的一些sintax或参数定义问题,您可能想看看这里。
这应该是你的项目出现问题的原因。
相关文章:
- Windows C++:文件夹移动访问被拒绝错误
- 尝试通过多个函数移动数组,但遇到了我不知道如何修复的错误
- emplace_back和push_back给出错误'double free or corruption (fasttop)'尽管定义了复制和移动构造函数
- std::任何只用于移动的模板,其中副本ctor内的static_assert等于编译错误,但为什么
- 编译器错误:只需要复制省略,但似乎需要移动构造函数(通过编译器)
- 为什么将双端移动到向量时出现 C26486 编译器错误?
- 我的移动分配操作程序重载的分段错误
- 错误:移动文件时'QString'为非标量类型"std::__cxx11::字符串"
- 错误:移动承诺时"Attempt to use a deleted function"
- C++所有 AT 命令的短信返回错误 |PC<->通过蓝牙和winsocket的移动连接
- "<某些系统标头>:错误:"<在此处插入函数>"在移动源文件后不是"std"的成员
- 移动和模板构造函数,错误的一个
- 将代码移动到函数中时,DLL "myApp.exe"中找不到序号错误0xC0000138
- 模型对话框移动到主窗口后面的Qt错误
- C++错误:在移动构造函数中使用已删除的函数
- 提升移动编译错误
- GTEST链接错误(从GCC 4.X移动到GCC 7.x)
- 为什么删除移动构造函数会导致编译错误
- 将函数从控制台应用程序移动到共享库项目似乎会带来不相关的编译错误
- 在数组中移动元素 SIGABRT 错误