Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument type for Qt signal and slot, does const reference qualifiers matters?

Tags:

For signal and slot of below type

signals:     void textChanged(const QString &);  public slots:     void setText(const QString & text) 

the type of argument of textChanged and setText seems to work invarable of const and &. Does the constant and reference qualification make any difference compared to just using QString ?

QObject::connect(a,SIGNAL(textChanged(QString)),b,SLOT(setText(QString))); QObject::connect(a,SIGNAL(textChanged(const QString &)),b,SLOT(setText(const QString &))); 

EDIT: I did not notice the output window showing error messages when there is incompatible type being used in SIGNAL or SLOT. I thought the signal slot mechanism is capable of detecting argument type error at compile time.

like image 414
yesraaj Avatar asked Dec 20 '09 07:12

yesraaj


People also ask

How signal and slot works in Qt?

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.

What is queued connection in Qt?

Queued Connection The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread. Blocking Queued Connection The slot is invoked as for the Queued Connection, except the current thread blocks until the slot returns.

How Qt event loops work?

Event loop of another thread is started by default implementation of QThread::run . When Qt decides it's time to process an event, it executes its event handler. While event handler is working, Qt has no chance to process any other event (unless given directly by QApplication::processEvents() or some other methods).


1 Answers

Qt checks a normalized signature, meaning

Normalization reduces whitespace to a minimum, moves 'const' to the front where appropriate, removes 'const' from value types and replaces const references with values.

like image 95
e8johan Avatar answered Sep 27 '22 02:09

e8johan