Slot default parameter generates error



  • 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?


  • Moderators

    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



  • Allright I understand, thanks!


  • Lifetime Qt Champion

    Hi,

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.