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("0x%1").arg ambiguous ?

QString("0x%1").arg ambiguous ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 5 Posters 794 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have:

    strData += QString("0x%1").arg((char)arybytData[i], 0, 16);
    

    What is ambiguous about this ?
    I'm getting:

    call of overloaded 'arg(char, int, int)' is ambiguous, I thought I had solved the ambiguity by specifing the types?

    Kind Regards,
    Sy

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • KroMignonK KroMignon

      @SPlatten said in QString("0x%1").arg ambiguous ?:

      strData += QString("0x%1").arg((char)arybytData[i], 0, 16);

      What is ambiguous about this ?

      to solve the ambiguity, you have to double cast: strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #4

      @KroMignon said in QString("0x%1").arg ambiguous ?:

      strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

      😱
      I think I'm getting a little bit sick....

      QStringLiteral("0x%1").arg(QString::number(arybytData[0], 16));
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • SPlattenS SPlatten

        I have:

        strData += QString("0x%1").arg((char)arybytData[i], 0, 16);
        

        What is ambiguous about this ?
        I'm getting:

        call of overloaded 'arg(char, int, int)' is ambiguous, I thought I had solved the ambiguity by specifing the types?
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @SPlatten There is no arg(char, int, int).
        There is arg(char a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • SPlattenS SPlatten

          I have:

          strData += QString("0x%1").arg((char)arybytData[i], 0, 16);
          

          What is ambiguous about this ?
          I'm getting:

          call of overloaded 'arg(char, int, int)' is ambiguous, I thought I had solved the ambiguity by specifing the types?
          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #3

          @SPlatten said in QString("0x%1").arg ambiguous ?:

          strData += QString("0x%1").arg((char)arybytData[i], 0, 16);

          What is ambiguous about this ?

          to solve the ambiguity, you have to double cast: strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

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

          J.HilkJ M 2 Replies Last reply
          1
          • KroMignonK KroMignon

            @SPlatten said in QString("0x%1").arg ambiguous ?:

            strData += QString("0x%1").arg((char)arybytData[i], 0, 16);

            What is ambiguous about this ?

            to solve the ambiguity, you have to double cast: strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @KroMignon said in QString("0x%1").arg ambiguous ?:

            strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

            😱
            I think I'm getting a little bit sick....

            QStringLiteral("0x%1").arg(QString::number(arybytData[0], 16));
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            2
            • KroMignonK KroMignon

              @SPlatten said in QString("0x%1").arg ambiguous ?:

              strData += QString("0x%1").arg((char)arybytData[i], 0, 16);

              What is ambiguous about this ?

              to solve the ambiguity, you have to double cast: strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

              M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #5

              @KroMignon said in [QString("0x%1").arg ambiguous ?]

              to solve the ambiguity, you have to double cast: strData += QString("0x%1").arg(int(char(arybytData[i])), 0, 16);

              I agree, but I would convert to uchar instead:

              char c=128;  // signed char !
              QString s1=QString("%1").arg(int(c),0,16);          // ffffffffffffff80"
              QString s2=QString("%1").arg(int(uchar(c)),0,16);   // 80
              
              or simply
              QString s1=QString("%1").arg(uint8_t(c),0,16);
              
              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