Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-24487

Allow multi-line srings in javascript blocks

    XMLWordPrintable

Details

    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

        1. test.qml
          1 kB
          Matthew Vogt (closed Nokia identity)

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              mvogt Matthew Vogt (closed Nokia identity) (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes