1
votes

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?

1
The main window is no different than any other QWidget in this regard.drescherjm
@drescherjm: or any qobject.lpapp
Maybe you could be interested in this: stackoverflow.com/questions/26422154/…Silicomancer

1 Answers

1
votes

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));