Presence and location of a property in a QML singleton source results in arbitrary bugs

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:59:40

问题


So I was finally able to reproduce it in an MCVE:

// S_Settings.qml
pragma Singleton
import QtQuick 2.7

Item {
  property real bsize: 50
}

// in main()
qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/S_Settings.qml")), "Set", 1, 0, "SS");

// main.qml
import QtQuick 2.7
import QtQuick.Window 2.2
import Set 1.0

Window {
  id: main
  visible: true
  width: 300
  height: 200

  Rectangle {
    anchors.centerIn: parent
    width: SS.bsize * 4
    height: SS.bsize * 2
    radius: SS.bsize * .5
    color: "red"
    border.color: "black"
    border.width: SS.bsize * .1
  }
}

This produces the expected result:

Now changing things a bit:

// S_Settings.qml
pragma Singleton
import QtQuick 2.7

Item {
  property real bsize: 50
  property real tenth: bsize * .1
  property real half: bsize * .5
}

// main.qml
import QtQuick 2.7
import QtQuick.Window 2.2
import Set 1.0

Window {
  id: main
  visible: true
  width: 300
  height: 200

  Rectangle {
    anchors.centerIn: parent
    width: SS.bsize * 4
    height: SS.bsize * 2
    radius: SS.half
    color: "red"
    border.color: "black"
    border.width: SS.tenth
  }
}

This in my particular case happens to produce no visible difference, unlike in the more complex production code, where it immediately produced visible bugs, seemingly everything is OK, but only seemingly.

Then, in the singleton QML file, push the last line one line up (so that half comes before tenth), and the result is as follows:

Push it another line up, and the result:

The result is all messed up now. In this small example it only caused the property values to corrupt, in my production code on top of that it also caused properties types to corrupt, causing the QML engine to see colors as ints, strings as bools, ints as nulls and similar crazy stuff.

So, is it reproducible? Any idea what's going on?

Update: Apparently this is one of the issues which plague the usage of the qml cache compiler.

A viable option to avoid the whole issue is to simply disable the cache via qputenv("QML_DISABLE_DISK_CACHE", "true"); first thing in main().

来源:https://stackoverflow.com/questions/41903160/presence-and-location-of-a-property-in-a-qml-singleton-source-results-in-arbitra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!