【问题标题】:Work around for QString mobile bug解决 QString 移动错误
【发布时间】: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


【解决方案1】:

您当前版本的文件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 或参数定义问题,因为您可能想看看 here .

这应该是您的项目出现问题的原因。

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 2023-03-16
    • 2023-02-15
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多