PDA

View Full Version : closeEvent help needed



sgmurphy19
5th November 2007, 17:25
Okay, I have to be missing something here.

I have a QDialog called "form":
In form.h:
protected:
void closeEvent(QCloseEvent *event);

In form.cpp:
void Form::closeEvent(QCloseEvent *event)
{
QMessageBox::information(NULL, "here", "Closing the Form");
gui->MainForm->tabWidget_Survey->setEnabled(true);
event->accept();
}

This is to capture when a user clicks the "X" at the top of the form.I put the message box there just as a test but nothing happens. Does something need to be connected?

Thanks,
Sean

momesana
5th November 2007, 17:51
Actually it should work. No connections are needed since this is done via eventHandling. Here is a minimal application that does work but without forms (I never use designer):


#include <QApplication>
#include <QtGui>

class Dialog : public QDialog
{
Q_OBJECT
public: Dialog(QWidget* parent=0) : QDialog(parent){}
protected: void closeEvent(QCloseEvent* e) { QMessageBox::information(NULL, "here", "closing the app"); }
};

#include "main.moc"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Dialog d;
d.show();
return app.exec();
}

Compare with your example. You can save it as main.cpp, do qmake and friends and run it to see whether it works.

cheers