Search code examples
qtqt4

How we can connect the signals and slot with different arguments?


In Qt, signals and slots require matching argument types:

QObject::connect: Incompatible sender/receiver arguments QLabel::linkActivated(QString) --> Button::call(int)

How can I implement a combination like this?


Solution

  • A simple method is to have an intermediate slot that calls the slot that you want. e.g.

    connect(src, SIGNAL(linkActivated(QString)), this, SLOT(receiveLink(QString)));
    

    and then

    void receiveLink(QString blah)
    {
      int response = someFunction(blah);
      mybutton->call(response);
    }
    

    You have to define some way to interpret the string into an int.