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. QString(" %1 of %2").arg(...); whats happening?
Forum Updated to NodeBB v4.3 + New Features

QString(" %1 of %2").arg(...); whats happening?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 5.0k Views 2 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I am trying to format 1 or N into a string with:

    quint16 uint16Part = 1, uint16Parts = 2;
    QString strOutput("    Debug:");
    strOutput += QString(" %1 of %2").arg(uint16Part, uint16Parts);
    

    The values assigned above are just for demonstration purposes. What I see in strOutput after the last operation is:

    "   Debug:                                    1 of %2"
    

    Why? I was expecting:

    "  Debug: 1 of 2"
    

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #2

      Solved, changing to:

      strOutput += QString(" %1 of %2").arg(uint16Part).arg(uint16Parts);
      

      Kind Regards,
      Sy

      ODБOïO 1 Reply Last reply
      3
      • SPlattenS SPlatten

        Solved, changing to:

        strOutput += QString(" %1 of %2").arg(uint16Part).arg(uint16Parts);
        
        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @SPlatten hi
        you can do

        strOutput += QString("%1 of %2").arg(uint16Part).arg(uint16Parts);
        
        SPlattenS 1 Reply Last reply
        1
        • ODБOïO ODБOï

          @SPlatten hi
          you can do

          strOutput += QString("%1 of %2").arg(uint16Part).arg(uint16Parts);
          
          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #4

          @LeLev , thank you, I must have been typing my own response whilst you were.

          Kind Regards,
          Sy

          1 Reply Last reply
          1
          • HoMaH Offline
            HoMaH Offline
            HoMa
            wrote on last edited by
            #5

            on the "why": the variants of arg(...) with an int as second argument assume this to be the field width into which the first argument should be fitted into.
            For multiple replacements you need all arguments to be QStrings.
            Check the documentation: https://doc.qt.io/qt-5/qstring.html#arg-3

            Regards
            Holger

            1 Reply Last reply
            1
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #6

              Not sure where is states that and it doesn't work.

              Kind Regards,
              Sy

              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