Results 1 to 2 of 2

Thread: closeEvent help needed

  1. #1
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default closeEvent help needed

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: closeEvent help needed

    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):
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. class Dialog : public QDialog
    5. {
    6. Q_OBJECT
    7. public: Dialog(QWidget* parent=0) : QDialog(parent){}
    8. protected: void closeEvent(QCloseEvent* e) { QMessageBox::information(NULL, "here", "closing the app"); }
    9. };
    10.  
    11. #include "main.moc"
    12. int main(int argc, char* argv[])
    13. {
    14. QApplication app(argc, argv);
    15. Dialog d;
    16. d.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Compare with your example. You can save it as main.cpp, do qmake and friends and run it to see whether it works.

    cheers

Similar Threads

  1. QPushButton not calling repaint when needed?
    By Enygma in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2010, 18:03
  2. QDevelop documentation, help needed.
    By jlbrd in forum Qt-based Software
    Replies: 0
    Last Post: 29th August 2007, 10:40
  3. Help needed with QAbstractItemModel
    By Harvey West in forum Qt Programming
    Replies: 11
    Last Post: 27th November 2006, 13:06
  4. help needed regarding QWT
    By skatakam in forum Qwt
    Replies: 1
    Last Post: 21st March 2006, 13:47
  5. qt windows help needed
    By dave in forum Newbie
    Replies: 19
    Last Post: 1st February 2006, 09:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.