PDA

View Full Version : What is passed into SIGNAL/SLOT function parameters?



Plissken
20th January 2011, 00:17
What is passed into SIGNAL/SLOT function parameters?


connect( lineEdit, SIGNAL( textChanged(const QString &) ),
this, SLOT( enableFindButton(const QString &) ) );

void FindDialog::enableFindButton( const QString &text )
{
findButton->setEnabled( !text.isEmpty() );
}

enableFindButton is called (by who exactly? The operating system?) but what is passed into const QString &? Obviously it's either going to be an empty string or not but what value does it hold? Do most if not all signals and slots of your own creation have to have a parameter?

Zlatomir
20th January 2011, 00:23
The signals/slots will have parameter or not depending on what you need to achieve with them.

The slot will be called when the signal is emitted, you will see in that example something like:

emit textChanged(someString); //where someString is a QString, most likely written by the user in some lineedit

Recommended reading signal/slot documentation (http://doc.qt.nokia.com/4.7/signalsandslots.html) (documentation is a good companion for any book)

LE: actually your lineEdit will emit the signal whenever it's text is changed
Sorry i just saw that it's an signal of a QWidget (QLineEdit) not one of declared in your class...

Plissken
20th January 2011, 00:26
But what if the slot is not called by an emit, by me specifically?

EDIT: Ah, Zlatomir. So, lineEdit sends an emit....does it pass into the parameter whatever is inside the text field?

Zlatomir
20th January 2011, 00:39
The slots can be called, just like any other member functions. Was that the answer?

And the signals you declare (you don't define them) you emit with: emit YOUR_SIGNAL_NAME(); whenever is you need to signal something (depending on your application) and all the slots connected with that signal will be called.

Added after 5 minutes:


EDIT: Ah, Zlatomir. So, lineEdit sends an emit....does it pass into the parameter whatever is inside the text field?

Yep, i corrected that a little bit later, in the beggining i thougth the signal was declared by you, then i saw that is a signal of one QWidget...
See the signal description in the documentation (http://doc.qt.nokia.com/latest/qlineedit.html#textChanged)

Plissken
20th January 2011, 01:03
Thank you.