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

前端 未结 4 1074
温柔的废话
温柔的废话 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 14:19

    From the signals slots documentation:

    The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)

    This means that a signal of the form

    signal(int, int, QString)

    can only be connected with slots with the following signatures

    slot1(int, int, QString)
    slot2(int, int)
    slot3(int)
    slot4()
    

    As koan suggests the best approach is to use another slot with a QString argument and then call the slot you actually want.

提交回复
热议问题