PDA

View Full Version : CloseEvent error



hollowhead
10th March 2012, 10:35
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.




#ifndef QTSOLARDATAMAINWINDOW_H
#define QTSOLARDATAMAINWINDOW_H
#include <QMainWindow>

class QCloseEvent; // foward declaration of class


namespace Ui {
class QtSolarDataMainWindow;
}



class QtSolarDataMainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit QtSolarDataMainWindow(QWidget *parent = 0);
~QtSolarDataMainWindow();

protected:

void closeEvent(QCloseEvent *event);

private:
Ui::QtSolarDataMainWindow *ui;

private slots:

};

#endif // QTSOLARDATAMAINWINDOW_H



and



include "qtsolardatamainwindow.h"
#include "ui_qtsolardatamainwindow.h"
#include <QCloseEvent>


QtSolarDataMainWindow::QtSolarDataMainWindow(QWidg et *parent) :
QMainWindow(parent),
ui(new Ui::QtSolarDataMainWindow)
{
ui->setupUi(this);

// signals and slots on constructor


// file menu
connect(action_Quit_Ctrl_Q, SIGNAL(triggered()), this, SLOT(close()));

}


QtSolarDataMainWindow::~QtSolarDataMainWindow()
{
delete ui;
}


void QtSolarDataMainWindow::closeEvent(QCloseEvent *event)
{

// writeSettings();
event->accept();

}



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.

Lesiok
10th March 2012, 11:15
Maybe line 16 should be :

connect(ui->action_Quit_Ctrl_Q, SIGNAL(triggered()), this, SLOT(close()));

hollowhead
10th March 2012, 11:21
Thanks I had missed the



ui->setupUi(this);



above.

In my other app its




setupUi(this);


Works.