Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Condition in QString .arg() ?

[solved] Condition in QString .arg() ?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by
    #1

    Is it possible to place a condition inside .arg() of a QString.

    e.g. something like this :

    @ QString hello = QString("hello %1, how are you")
    .arg( ?cond? );

        ?cond? : 
               
        if (TRUE) {
            return "Joe"
        } else {
            return "Harry"
        }
                       
        qDebug() << hello;@
    
    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      @ QString hello = QString("hello %1, how are you") .arg((TRUE)?QStringLiteral("Joe"):QStringLiteral("Harry"));@

      Like that?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted28
        wrote on last edited by
        #3

        Yes, exectly , thank you !

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deleted28
          wrote on last edited by
          #4

          bq. QStringLiteral is a new macro introduced in Qt 5 to create ...

          error: 'QStringLiteral' was not declared in this scope

          seems not available in Qt 4.8.1 (?)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You can use QLatin1String in case of Qt 4.8

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deleted28
              wrote on last edited by
              #6

              yes,
              the condition was my main problem and this i learned now :)

              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