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 String Formatting

Multiline String Formatting

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtcreatorqmlqtquickformatterstring
3 Posts 3 Posters 931 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
    stewythe1st
    wrote on last edited by stewythe1st
    #1

    What is the recommended way to handle multiline strings in QML source code? I have some examples of elements with long static text strings. They look vaguely like the following. Some of the descriptions can get quite long and take up several lines when wrapped. If I was writing C code, and using a tool like Clang-Format, this would automatically get wrapped and formatted. However the QML formatter (QtCreator -> "Tools" -> "QML/JS" -> "Reformat file") doesn't do this. Its annoying to work with or review long strings like this in code review if they're not wrapped. And its a pain to manually mess with string concatenation operators, parentheses, newlines every time we add or modify a long string.

    So am I doing this wrong? Should I be storing these strings somewhere else or writing my code in a different way? If this is the recommended way, is there any means of formatting this?

    CustomItem {
      title: qsTr("Setting")
      description: qsTr("Adjusting this value will change some setting. Blah blah blah. Blah blah blah. Blah blah blah. Blah blah blah. Long static text description.")
      value: 0
    }
    

    Edit: To clarify, I am strictly asking about how to format my source code. The text gets wrapped perfectly fine in the actual application at runtime.

    M 1 Reply Last reply
    1
    • S stewythe1st

      What is the recommended way to handle multiline strings in QML source code? I have some examples of elements with long static text strings. They look vaguely like the following. Some of the descriptions can get quite long and take up several lines when wrapped. If I was writing C code, and using a tool like Clang-Format, this would automatically get wrapped and formatted. However the QML formatter (QtCreator -> "Tools" -> "QML/JS" -> "Reformat file") doesn't do this. Its annoying to work with or review long strings like this in code review if they're not wrapped. And its a pain to manually mess with string concatenation operators, parentheses, newlines every time we add or modify a long string.

      So am I doing this wrong? Should I be storing these strings somewhere else or writing my code in a different way? If this is the recommended way, is there any means of formatting this?

      CustomItem {
        title: qsTr("Setting")
        description: qsTr("Adjusting this value will change some setting. Blah blah blah. Blah blah blah. Blah blah blah. Blah blah blah. Long static text description.")
        value: 0
      }
      

      Edit: To clarify, I am strictly asking about how to format my source code. The text gets wrapped perfectly fine in the actual application at runtime.

      M Offline
      M Offline
      Moo-san
      wrote on last edited by Moo-san
      #2

      @stewythe1st Did you find any solution to this? I find it ridiculous that QML seemingly lacks the tools to format multiline strings in the source code.

      Using string concatenation ("string" + "string"…) works but is unbeliavably cumbersome.

      1 Reply Last reply
      0
      • johngodJ Offline
        johngodJ Offline
        johngod
        wrote on last edited by
        #3

        I use

        qsTr(" sopdk apdapo dapodk aspod ad\n"
        + "ssdkopaksdopakdp ksopdak opdad\n"
        + "aiojdaios daoisd jaoidu aoidi adoia dj" )
        

        Let me know if someone uses other solutions

        1 Reply Last reply
        0

        • Login

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