Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 995
user896036 Avatar asked Oct 28 '11 08:10

user896036


People also ask

How do you use slots and signals?

In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.

Can we connect signal to signal in Qt?

This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal.


1 Answers

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.

like image 170
pnezis Avatar answered Oct 03 '22 15:10

pnezis