2
votes

I have created a QMainWindow using QT Designer. I have components that have signals slots. I've made some non-gui components QObjects so I can also use the signal/slot mechanism.

My next step was to add a modeless dialog. I do not want the dialog to block the main window. I would like the dialog to remain active(somewhere visible to the user or in the background) until the user clicks to close it. I created a modeless QDialog object with designer. The dialog pops up as needed. It keeps the information from the previous session in the text box as well. It's just a filename.

However, when I started to connect the QDialog to the QMainWindow, the signal/slot mechanism does not appear to work.

This is my code:

//In the .h file declared as member of the QMainWindow
ScriptDialog *theScriptDialog;

//In the .cpp file, the constructor of QMainWindow
theScriptDialog = new ScriptDialog(this);

QObject::connect(theScriptDialog, SIGNAL(notifyStartScript(QString)), SLOT   (startScripting(QString)));

Maybe I am barking up the wrong tree. Is there a better way to create a pop up window like this?

1

1 Answers

0
votes

First see if the connect succeeds: check applications console output for a warning about failed connect, then print return value of connect call.

Then some things to do:

  • You have the Q_OBJECT macro in scriptdialog.h
  • You remembered to run qmake after adding new Q_OBJECT classes
  • Add qDebug print/breakpoint to where notifyStartScript is emitted
  • Connect something else to startScripting slot, with qDebug print or breakpoint, to verify it gets called
  • If you have used in-source builds (like just running qmake and make from command line at source dir), then switched to 'shadow build' in separate build dir, make sure the source dir is clean of generated .cpp, .h and .o files.