I'm trying to use a QAction (QMenu member entry) to open a new window. Precisely: I want actionAbout signal predefined activated to match MainWindow custom slot open AboutWindow - and that's what I've got trouble with.
I know that I can use either the connect Qt function manually inside the source main_window.cpp file or just click it up in the Qt Creator, but my custom slot doesn't show up so I cannot select it. Maybe my slot function declaration is wrong (invalid parameters) and that's why QtCreator doesn't allow me to choose my custom slot in the GUI signals & slots. Could anyone point me what should I do to make QtCreator display my custom slot in the dropdown and how should the connect function call look like?
This is my main_window.h file content:
#include
#include "about_window.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void openAboutWindow();
private:
Ui::MainWindow *ui;
Ui::AboutWindow *aboutWindow;
};
And this is main_window.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(actionAbout, SIGNAL(activated()), this, SLOT(openAboutWindow(this));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openAboutWindow(QWidget *parent)
{
aboutWindow = new Ui::AboutWindow(parent); // Be sure to destroy you window somewhere
aboutWindow->show();
}
The compiler shouts about both constructor and openAbutWindow:
../Application/main_window.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’: ../Application/main_window.cpp:9:13: error: ‘actionAbout’ was not declared in this scope ../Application/main_window.cpp:9:80: error: expected ‘)’ before ‘;’ token ../Application/main_window.cpp: In member function ‘void MainWindow::openAboutWindow(QWidget*)’: ../Application/main_window.cpp:19:44: error: invalid use of incomplete type ‘struct Ui::AboutWindow’ ../Application/about_window.h:7:11: error: forward declaration of ‘struct Ui::AboutWindow’ ../Application/main_window.cpp:20:15: error: invalid use of incomplete type ‘struct Ui::AboutWindow’ ../Application/about_window.h:7:11: error: forward declaration of ‘struct Ui::AboutWindow’