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. Slot default parameter generates error

Slot default parameter generates error

Scheduled Pinned Locked Moved Solved General and Desktop
slotdefault argumen
4 Posts 3 Posters 1.1k 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.
  • M Offline
    M Offline
    michelson
    wrote on last edited by michelson
    #1

    When i set first slot default parameter i get an error:

    //OK
    void on_setId( QByteArray id );
    void on_setId( QString id = QString("something"));
    
    //ERROR
    void on_setId( QByteArray id = QByteArray::fromStdString("something"); //<--
    void on_setId( QString id = QString("something"));
    

    Error:

    \moc_rej006.cpp:314: error: call of overloaded 'on_setId()' is ambiguous
             case 34: _t->on_setId(); break;
                                   ^
    

    Moc is creating some weird cases for (non existing) functions:

    case 34: _t->on_setId(); break;
    case 35: _t->on_setId((*reinterpret_cast< QString(*)>(_a[1]))); break;
    case 36: _t->on_setId(); break;
    

    I dont have on_setId() which takes no parameters...
    Whats wrong with this one? I mean why setting default parameter generates this error?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This is invalid C++.
      If you now call on_setId() how should compiler know which of on_setId() it should call?
      The compiler error says the same: \moc_rej006.cpp:314: error: call of overloaded 'on_setId()' is ambiguous

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

      1 Reply Last reply
      2
      • M Offline
        M Offline
        michelson
        wrote on last edited by
        #3

        Allright I understand, thanks!

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

          Hi,

          On a side note, there's no need to use fromStdString to initialize a QByteArray with a string.

          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

          • Login

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