I've seen alot of examples online about signals and slots, but none that show you how to emit a signal from your mainwindow class and connect into another slot of another window class. Assume the signal emitted from the mainwindow is a bool type and if it's a 1, I want to connect it to another slot from some other class. I've always seen it done the other way around. Can someone explain the most efficient way to accomplish this?
Asked
Active
Viewed 1,554 times
1
-
The main window is no different than any other QWidget in this regard. – drescherjm Dec 18 '14 at 18:13
-
1@drescherjm: or any qobject. – László Papp Dec 20 '14 at 17:21
-
Maybe you could be interested in this: http://stackoverflow.com/questions/26422154/my-slot-is-not-invoked-called-used-working-executed – Silicomancer Dec 22 '14 at 23:04
1 Answers
1
First, you need to inherit your own mainwindow, then add the Q_OBJECT macro and a signals section:
class myMainWindow : public QMainWindow
{
Q_OBJECT
signals:
void mySignal(bool someValue);
}
When you want to signal to be executed in your window code, you'd use
emit mySignal(true); // or false....
Then, you connect as usual:
connect(myWindowInstace, SIGNAL(mySignal(bool), someOtherWidget, SLOT(takesMySignal(bool));

Nicolas Holthaus
- 7,763
- 4
- 42
- 97