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 object, very odd behaviour!
Forum Updated to NodeBB v4.3 + New Features

QString object, very odd behaviour!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views 1 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.
  • G Offline
    G Offline
    gRicky
    wrote on last edited by
    #1

    Hi ALL,

    I'm having a very strange behaviour of my QString object. Here my code:
    @
    //the first line.
    QString s;
    s= "%1 %2 %3 %4";
    s.arg("a").arg("3").arg("0").arg("0");
    qDebug() << s.toAscii();

    //the second line.
    QString str;
    str = "%1 %2";
    str.arg("", "Hello");
    qDebug() << str.toAscii();
    @

    The strange is that even though I was waiting for the “3 3 0 0” as answer for the first line and, “ Hello” for the second line in the debug window; I’m receiving “%1 %2 %3 %4” as result of the first line and “%1 %2” as result for the second one. Why I’m having this behaviour? Where is my mistake? behaviour? Where is my mistake?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomma
      wrote on last edited by
      #2

      QString::arg() returns copy of string with place marker(s) replaced.
      You are printing original string.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gRicky
        wrote on last edited by
        #3

        [quote author="Tomma" date="1355740883"]QString::arg() returns copy of string with place marker(s) replaced.
        You are printing original string.[/quote]

        I'm sorry but I didn't understand!

        I'm copy the sample got from the QString documentation, here the "link":http://qt-project.org/doc/qt-4.8/qstring.html#arg-2http://. So, please, could you make a sample?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gRicky
          wrote on last edited by
          #4

          Ok...
          I understood!

          It is simple to do this (just for the first line):

          @
          QString s, msg;
          s= "%1 %2 %3 %4";
          msg=s.arg("a").arg("3").arg("0").arg("0");
          qDebug() << msg;
          @

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gRicky
            wrote on last edited by
            #5

            thank you for your time!!

            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