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>
namespace Ui {
class QtSolarDataMainWindow;
}
{
Q_OBJECT
public:
explicit QtSolarDataMainWindow
(QWidget *parent
= 0);
~QtSolarDataMainWindow();
protected:
private:
Ui::QtSolarDataMainWindow *ui;
private slots:
};
#endif // QTSOLARDATAMAINWINDOW_H
#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
To copy to clipboard, switch view to plain text mode
and
include "qtsolardatamainwindow.h"
#include "ui_qtsolardatamainwindow.h"
#include <QCloseEvent>
QtSolarDataMainWindow
::QtSolarDataMainWindow(QWidget *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();
}
include "qtsolardatamainwindow.h"
#include "ui_qtsolardatamainwindow.h"
#include <QCloseEvent>
QtSolarDataMainWindow::QtSolarDataMainWindow(QWidget *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();
}
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.
Bookmarks