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

前端 未结 4 1077
温柔的废话
温柔的废话 2021-02-02 13:16

In Qt, signals and slots require matching argument types:

QObject::connect: Incompatible sender/receiver arguments QLabel::linkActivated(QString) --> Butt

4条回答
  •  生来不讨喜
    2021-02-02 13:55

    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.

提交回复
热议问题