PDA

View Full Version : Indicating/catching signals



Tomasz
30th September 2010, 12:55
Hello!

I've got in my header file signal:



signals:
void mySignal(int i);


Sometimes mySignal(int i) is emitted by different slots:



connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunc));

[...]

void MainWindow::myFunc()
{
mySignal(10);
}


How can I catch that signal?

thanks in advance
best regards
Tomasz

tbscope
30th September 2010, 13:00
That should be

emit mysignal(10);

And:
http://doc.qt.nokia.com/4.7/qsignalspy.html

Tomasz
30th September 2010, 13:35
Would it be wrong if I do it that way:



connect(pushButton, SIGNAL(clicked()), this, SLOT(myFunc()));
connect(this, SIGNAL(mySignal(int), this, SLOT(myOtherFunc(int)));

[...]

void MainWindow::myFunc()
{
mySignal(10);
}


I've tried this, and it works, but I don't know if it's correct use of signals.

thanks in advance
best regards
Tomasz

tbscope
30th September 2010, 14:18
Sure, there's no problem with that.

squidge
30th September 2010, 14:22
That should be

emit mysignal(10);But 'emit' is only syntactic suger. You can omit and save the keystrokes at the expense of code readability.

tbscope
30th September 2010, 14:24
But 'emit' is only syntactic suger. You can omit and save the keystrokes at the expense of code readability.
I honnestly didn't know that.