1

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?

deusmaximus
  • 73
  • 1
  • 8

1 Answers1

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