QML Singleton Parse错误

时间:2018-04-10 18:16:11

标签: qt qml

我有一个QML单例文件,我用它来保存在应用程序中使用的用户变量。 我使用相同的文件在C ++中存储#define之类的变量。 问题是如果我添加新参数并编译并运行应用程序,我从单例文件中的旧变量读取的值将读取垃圾值,直到我添加console.log()。 每次我向文件添加新变量时都会发生这种情况。

这是一个已知的错误吗?我在Yocto构建中使用Qt 5.8。

修改:添加了最小的项目文件以重现错误。我也在Ubuntu 16中试过这个。

main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Test")

    Scene
    {
        width: parent.width
        height: parent.height
        anchors.centerIn: parent
    }
}

Style.qml

pragma Singleton
import QtQuick 2.0
QtObject
{
    property color green: "#558B2F"
    property color red: "#DD2C00"
    property color black: "black"

    property int dialogPopupDuaration: 100
    property int dialogTimeoutValue : 1500
    property int splashTimeout: 5000
    property int rotation: 180

    //Dialog Types
    property int dialogInfo: 0
    property int dialogProcessing: 1
    property int dialogSuccess: 2
    property int dialogFailure: 3

    //Settings
    property int manualOffset: 0
    property int calibrationTimeout: 1
    property bool isUnitMM: true
    property bool isBrightnessHigh: false
    property bool isDMPInit: false
    property int batteryThreshold: 33
    property int batterWarningOffset: 3

    //Uncomment the below lines and run
    //the app will no longer print the qW
    //until i console.log() in main.qml

//            readonly property int boneS: 1
//            readonly property int boneN: 0
//            property int boneType: boneS

//            property int boneTN: boneN
//            property int boneTP: boneN

    //Default quaternion values for the 3D obj
    //to face towards the screen
    property real qX: 0.0
    property real qY: -1.0
    property real qZ: 0.0
    property real qW: -0.5

    property real tolerance: 0.02

    //IMU requires 30s from boot to settle down
    //so if user tries to calibrate it before that
    //use this bool to show warning
    property bool isThirtySecElapsed: false

    readonly property string appVersion: "v1.0.2"
}

Scene.qml

import QtQuick 2.0
import "."

Rectangle
{
    id: scene
    anchors.fill: parent
    width: parent.width * 0.5
    height: width
    color: "grey"
    Text
    {
        text: Style.qW
        anchors.centerIn: parent
        font.bold: true
        font.pointSize: 20
        fontSizeMode: Text.Fit
        color: "white"
    }

    Component.onCompleted:
    {
        //console.log(Style.qW)
    }
}

qmldir

singleton Style 1.0 Style.qml

0 个答案:

没有答案