0
votes

After opening a dialog window from my main window, I call a function to connect confirmSavePathButton and confirmLoadPathButton to their individual file-writing and reading functions separately. The function called by the main window to open the dialog with a button works and remains connected, but the connections in the called function do not work.

Camera_Control_GUI class contains mainwindow ui, VideoSettings class contains dialog window uiDlg. Both classes were generated by Qt.

I've tried changing the syntax used in the connect lines to pre-5.0 Qt, using SIGNALS and SLOTS. None of the connections on the dialog seem to be working.

Camera_Control_GUI.cpp:

    void Camera_Control_GUI::launchConfigOptions() {
QDialog* configOptions = new QDialog(0, 0);
Ui::VideoSettings uiDlg;
VideoSettings vidObj;

vidObj.videoSettingsConnector();
uiDlg.setupUi(configOptions);
configOptions->exec();
    }

VideoSettings.cpp:

void VideoSettings::videoSettingsConnector() {
connect(uiDlg->confirmSavePushButton, &QPushButton::clicked, this, &VideoSettings::pathWrite);
connect(uiDlg->confirmLoadPushButton, &QPushButton::clicked, this, VideoSettings::pathRead);
QMessageBox::about(this, "Verification Box", "This function is called");
}

Opening the dialog window using launchConfigOptions() shows the QMessageBox indicating the function has run. However, when attempting to click on either confirmSavePushButton or confirmLoadPushButton, neither run (also checked by replacing both functions with having a QMessageBox open).

1
Welcome to Stack Overflow! Given what you have shown, I really can not give you an idea what is going on. It would be helpful if you could provide a Minimal Reproducible Example that includes how you are checking that things don't work. You might want to check the return code of the connect(..) to make sure it is working. Also, I would think you want just &QPushButton::clicked without the static cast.jwernerny
Thank you, @jwernerny! I have attempted to add some more clarity, but have been unable to reproduce the problem. Part of the trouble is that I am not getting any errors associated with running the code. I am still new Qt, so I am unsure how to check why connect itself may have failed. Any further insight, including that I still have not provided enough information would be helpful. Thank you in advance.MobiusTetrakaidecagon

1 Answers

0
votes

You're running "uiDlg.setupUi" after running "vidObj.videoSettingsConnector". Your QPushButton instances are created by the setupUi call, so in your "connect" methods, you're connecting a pointer value of "0". Reverse the order of those two calls so that the QPushButton instances exist first.