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. Call to member function 'arg' is ambiguous.
Forum Updated to NodeBB v4.3 + New Features

Call to member function 'arg' is ambiguous.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 4.2k 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.
  • Atr0p0sA Offline
    Atr0p0sA Offline
    Atr0p0s
    wrote on last edited by Atr0p0s
    #1

    Hello citizens!
    With this simple code I get the error: Call to member function 'arg' is ambiguous.

    uint lng_abs = 3425;
    QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
    

    But arg function has definition with uint argument: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const

    At the same time I don't get the error using arg in the following way:

    QString lngFormatted = QString("%1").arg(lng_abs, 3);
    

    I could use arg(QString::number(lng_abs).rightJustified(3, '0')) in the first case, but for my better understanding, can you explain please, how to fix the first code example to use arg with all arguments?
    And why is 'arg' ambiguous, if I give it uint argument and arg has uint prototype?

    Thank you in advance!

    JonBJ 1 Reply Last reply
    0
    • Atr0p0sA Atr0p0s

      @JonB
      It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #5

      @Atr0p0s
      As @J-Hilk says. Explanation in https://www.qtcentre.org/threads/62640-Bug-Issue-compiler-is-confused-with-calling-simple-arg(int-int-int-QChar)-func- [our own @ChrisW67 :) ]

      C 1 Reply Last reply
      5
      • Atr0p0sA Atr0p0s

        Hello citizens!
        With this simple code I get the error: Call to member function 'arg' is ambiguous.

        uint lng_abs = 3425;
        QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
        

        But arg function has definition with uint argument: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const

        At the same time I don't get the error using arg in the following way:

        QString lngFormatted = QString("%1").arg(lng_abs, 3);
        

        I could use arg(QString::number(lng_abs).rightJustified(3, '0')) in the first case, but for my better understanding, can you explain please, how to fix the first code example to use arg with all arguments?
        And why is 'arg' ambiguous, if I give it uint argument and arg has uint prototype?

        Thank you in advance!

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #2

        @Atr0p0s
        There will be another overload which it could also match. When you get that error message, does the compiler output more lines of information indicating which ones match? My gcc does, and lets you see what all the alternatives are so that you can adjust to be precise, e.g. first line of several:

        /home/jon/QtTests/proxy/main.cpp:177: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
        main.cpp: In function ‘int main(int, char**)’:
        main.cpp:177:45: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
          177 |     QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
              |                            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
        
        Atr0p0sA 1 Reply Last reply
        0
        • JonBJ JonB

          @Atr0p0s
          There will be another overload which it could also match. When you get that error message, does the compiler output more lines of information indicating which ones match? My gcc does, and lets you see what all the alternatives are so that you can adjust to be precise, e.g. first line of several:

          /home/jon/QtTests/proxy/main.cpp:177: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
          main.cpp: In function ‘int main(int, char**)’:
          main.cpp:177:45: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
            177 |     QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, '0');
                |                            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
          
          Atr0p0sA Offline
          Atr0p0sA Offline
          Atr0p0s
          wrote on last edited by
          #3

          @JonB
          It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

          J.HilkJ JonBJ 2 Replies Last reply
          0
          • Atr0p0sA Atr0p0s

            @JonB
            It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

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

            @Atr0p0s said in Call to member function 'arg' is ambiguous.:

            Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

            But, did you really, or do you thing you did? :P

            go the full way:

            QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, QChar('0'));
            

            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.

            Atr0p0sA 1 Reply Last reply
            3
            • Atr0p0sA Atr0p0s

              @JonB
              It indicates that there are other arg functions with different arguments, but is there a way to use a uint function and don't get the warning? Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #5

              @Atr0p0s
              As @J-Hilk says. Explanation in https://www.qtcentre.org/threads/62640-Bug-Issue-compiler-is-confused-with-calling-simple-arg(int-int-int-QChar)-func- [our own @ChrisW67 :) ]

              C 1 Reply Last reply
              5
              • JonBJ JonB

                @Atr0p0s
                As @J-Hilk says. Explanation in https://www.qtcentre.org/threads/62640-Bug-Issue-compiler-is-confused-with-calling-simple-arg(int-int-int-QChar)-func- [our own @ChrisW67 :) ]

                C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #6

                @JonB Now that was a while ago

                1 Reply Last reply
                4
                • J.HilkJ J.Hilk

                  @Atr0p0s said in Call to member function 'arg' is ambiguous.:

                  Because I passed all arguments according to the declaration: QString QString::arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = u' ') const and still get the warning.

                  But, did you really, or do you thing you did? :P

                  go the full way:

                  QString lngFormatted = QString("%1").arg(lng_abs, 3, 10, QChar('0'));
                  
                  Atr0p0sA Offline
                  Atr0p0sA Offline
                  Atr0p0s
                  wrote on last edited by
                  #7

                  @J-Hilk It turns out that I thought so :)
                  @JonB @ChrisW67
                  Thanks for the help, I should be more thoughtful...

                  1 Reply Last reply
                  1
                  • Atr0p0sA Atr0p0s has marked this topic as solved on

                  • Login

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