Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Multiline strings
Forum Updated to NodeBB v4.3 + New Features

Multiline strings

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    I tryed to do the following to break a long string:

        ListElement {
            name: "Mercury"
            imageSource: "images/mercury.jpeg"
            facts: "Mercury is the smallest planet in the Solar System. " +
                   "It is the closest planet to the sun. It makes one trip " +
                   "around the Sun once every 87.969 days."
        }
    

    However I get complains that i cannot use script for property value.

    So what is the correct way to break longer strings on several lines for readability in qml?

    KroMignonK 1 Reply Last reply
    0
    • S Offline
      S Offline
      sandro4912
      wrote on last edited by
      #2

      What works:

          ListElement {
              name: "Mercury"
              imageSource: "images/mercury.jpeg"
              facts: "Mercury is the smallest planet in the Solar System. \
                     It is the closest planet to the sun. It makes one trip \
                     around the Sun once every 87.969 days."
          }
      

      Is that the best way?

      1 Reply Last reply
      0
      • MarkkyboyM Offline
        MarkkyboyM Offline
        Markkyboy
        wrote on last edited by
        #3

        "What is the best way?", - I think that is subjective, if it works, then....it works.

        You could also do;

            ListElement {
                name: "Mercury"
                imageSource: "images/mercury.jpeg"
                facts: "Mercury is the smallest planet in the Solar System.</p>
                        <p>It is the closest planet to the sun. It makes one trip</p>
                        <p>around the Sun once every 87.969 days.</p>"
            }
        

        Don't just sit there standing around, pick up a shovel and sweep up!

        I live by the sea, not in it.

        1 Reply Last reply
        2
        • S sandro4912

          I tryed to do the following to break a long string:

              ListElement {
                  name: "Mercury"
                  imageSource: "images/mercury.jpeg"
                  facts: "Mercury is the smallest planet in the Solar System. " +
                         "It is the closest planet to the sun. It makes one trip " +
                         "around the Sun once every 87.969 days."
              }
          

          However I get complains that i cannot use script for property value.

          So what is the correct way to break longer strings on several lines for readability in qml?

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #4

          @sandro4912 said in Multiline strings:

          So what is the correct way to break longer strings on several lines for readability in qml?

          Hello, this is not a problem about line break, but the way you construct the final string which is not compatible with ListElement limitation. Read this extract from documentation:

          The names used for roles must begin with a lower-case letter and should be common to all elements in a given model. Values must be simple constants; either strings (quoted and optionally within a call to QT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter).

          You can only use constants with ListElement
          So you have to use \ to continue the string on next line, or write all in one line. You cannot use string concatenation in this special case.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved