Custom sighnal in main window not recognized?
-
Hi there.. again..
Situation:
I have a MainWindow called tgs_mainwindow, and a Dialog called dialog_programsettings.Inside the Settings, the user should be able to select a color as editor background.
The Editor background color is changed in the mainwindow, via stylesheet.
Like this:qss = QString("#Area_DisplayContents {background: #" + EditorColor + "}"); ui->Area_DisplayContents->setStyleSheet(qss);
Where EditorColor is a QString with "FFFFFF" Format (without #)
The header of the dialog:
class Dialog_ProgramSettings : public QDialog { Q_OBJECT public: explicit Dialog_ProgramSettings(QWidget *parent = nullptr); ~Dialog_ProgramSettings(); signals: void recolorEditorUI(); private: Ui::Dialog_ProgramSettings *ui; private slots: void ShowColorDialog(); void recolorPreview(QColor col); };
Has a custom signal inside it. It gets emitted via a function in cpp. The Function is called, cause a testimage gets recolored with this function, too.
In the mainwindow cpp, i open the Dialog with this code:
Dialog_ProgramSettings *dialog = new Dialog_ProgramSettings(this); dialog->setWindowTitle(tr("Einstellungen")); dialog->exec(); connect(dialog, SIGNAL(recolorEditorUI()), this, SLOT(RecolorEditor()));
RecolorEditor is the Function, that recolors the Background.
This connection seems never to be triggered, cause the Background color never changes..What do i have to do, to make it work?
-
Call
connect()
before you callexec()
:-)Plus, two general remarks:
- if only possible, use the new connect syntax
- check return value of
connect()
to make sure the connection has actually been established