Results 1 to 3 of 3

Thread: CloseEvent error

  1. #1
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default CloseEvent error

    I've returned to programming after a while and so I'm rusty. I previously used Qdevelop and Qt 4.5 designer. I'm writing and designing another app in QtCreator. I decided to ease myself back in by getting my file -quit code to work. I copied and pasted the code over from my other app where it works. Surprise surprise it didn't work in the new one. By searching around I've managed to reduce the error to one. I've included CloseEvent in my mainwindow.cpp file and put a foward class declaration in my manwindow.hpp file something I did not have to do previously.

    Qt Code:
    1. #ifndef QTSOLARDATAMAINWINDOW_H
    2. #define QTSOLARDATAMAINWINDOW_H
    3. #include <QMainWindow>
    4.  
    5. class QCloseEvent; // foward declaration of class
    6.  
    7.  
    8. namespace Ui {
    9. class QtSolarDataMainWindow;
    10. }
    11.  
    12.  
    13.  
    14. class QtSolarDataMainWindow : public QMainWindow
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit QtSolarDataMainWindow(QWidget *parent = 0);
    20. ~QtSolarDataMainWindow();
    21.  
    22. protected:
    23.  
    24. void closeEvent(QCloseEvent *event);
    25.  
    26. private:
    27. Ui::QtSolarDataMainWindow *ui;
    28.  
    29. private slots:
    30.  
    31. };
    32.  
    33. #endif // QTSOLARDATAMAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. include "qtsolardatamainwindow.h"
    2. #include "ui_qtsolardatamainwindow.h"
    3. #include <QCloseEvent>
    4.  
    5.  
    6. QtSolarDataMainWindow::QtSolarDataMainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::QtSolarDataMainWindow)
    9. {
    10. ui->setupUi(this);
    11.  
    12. // signals and slots on constructor
    13.  
    14.  
    15. // file menu
    16. connect(action_Quit_Ctrl_Q, SIGNAL(triggered()), this, SLOT(close()));
    17.  
    18. }
    19.  
    20.  
    21. QtSolarDataMainWindow::~QtSolarDataMainWindow()
    22. {
    23. delete ui;
    24. }
    25.  
    26.  
    27. void QtSolarDataMainWindow::closeEvent(QCloseEvent *event)
    28. {
    29.  
    30. // writeSettings();
    31. event->accept();
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 

    I'm absolutely sure my signal has the right name that's its object name in the creator form designer. But its this line that is causing trouble

    qtsolardatamainwindow.cpp: In constructor ‘QtSolarDataMainWindow::QtSolarDataMainWindo w(QWidget*)’:
    qtsolardatamainwindow.cpp:16:13: error: ‘action_Quit_Ctrl_Q’ was not declared in this scope

    Where am I going wrong and just out of interest why the change? Thankyou very much.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CloseEvent error

    Maybe line 16 should be :
    Qt Code:
    1. connect(ui->action_Quit_Ctrl_Q, SIGNAL(triggered()), this, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: CloseEvent error

    Thanks I had missed the

    Qt Code:
    1. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    above.

    In my other app its

    Qt Code:
    1. setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    Works.

Similar Threads

  1. Can't override the closeEvent()
    By scot_hansen in forum Newbie
    Replies: 7
    Last Post: 5th October 2010, 22:47
  2. CloseEvent of QDockWidget
    By mstegehu in forum Qt Programming
    Replies: 5
    Last Post: 16th March 2010, 13:10
  3. QDialog and closeEvent
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2009, 02:07
  4. QSettings and closeEvent()
    By vito49 in forum Newbie
    Replies: 2
    Last Post: 13th October 2008, 16:18
  5. closeEvent
    By jochen_r in forum Newbie
    Replies: 7
    Last Post: 16th January 2006, 12:05

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
  •  
Qt is a trademark of The Qt Company.