Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.0.0
-
None
Description
QML developers will not have a clear understanding of the boundaries between QML and javascript code in QML files.
While allowing multiline strings in QML is clearly beneficial, it can also be very confusing when a developer finds that multiline strings can be used in some contexts but not in others, that appear to be equivalent. In the following function, it appears that the three object creation contexts are equivalent, while in fact one of the three does not permit multiline strings:
import QtQuick 2.0 Item { id: root; property var t1: null property var t2: null property var t3: null function doCreate() { return Qt.createQmlObject("import QtQuick 2.0; Item { objectName: 'test3'; }", root); } Component.onCompleted: { t1 = Qt.createQmlObject("import QtQuick 2.0; Item { objectName: 'test1'; }", root); console.log(t1.objectName); function doNestedCreate() { return Qt.createQmlObject("import QtQuick 2.0; Item { objectName: 'test2'; }", root); } t2 = doNestedCreate(); console.log(t2.objectName); t3 = doCreate(); console.log(t3.objectName); } }
Pre-processing multiline strings inside javascript blocks in QML woud alleviate this confusion.
Attachments
Issue Links
- relates to
-
QTBUG-22344 createQmlObject crashes under various circumstances
- Closed