Hi,
This seems so simple but I haven't been able to figure it out yet.. All help will be appreciated :)
I have tried to create a Mainwindow (mainwidget) with menubar holding an entry "Help", and I have created an "aboutAction"-item and dragged it into the help menu using the designer! Saved as main.ui! (check attachment)
I have three other files: mainwindow.cpp, mainwindow.h and main.cpp (see below) and it seems to compile as it should but when I try to execute the About action nothing happens.
I have tested the about() function by just executing it on program start and it shows a QMessageBox as intended, Now why doesn't the line:
connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) );
connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) );
To copy to clipboard, switch view to plain text mode
...seem to connect the menu-entry with the function
Thanks in advance :
Nikau
mainwindow.cpp
#include <QApplication>
#include <QStatusBar>
#include <QMessageBox>
#include "mainwindow.h"
{
ui.setupUi( this );
createActions();
statusBar()->showMessage( tr("Done") );
}
void Mainwindow::about()//works
{
tr("<h2>Mainwindow v. 0.01</h2>\n"
"An application to help test various aspects of QT4\n"
"Thanks to anybody helping out :-)\n") );
}
void Mainwindow::createActions()
{
aboutAction
= new QAction(tr
("&About"),
this);
connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) );
}
#include <QApplication>
#include <QStatusBar>
#include <QMessageBox>
#include "mainwindow.h"
Mainwindow::Mainwindow( QWidget *parent ) : QMainWindow( parent )
{
ui.setupUi( this );
createActions();
statusBar()->showMessage( tr("Done") );
}
void Mainwindow::about()//works
{
QMessageBox::about( this, tr("About Mainwindow"),
tr("<h2>Mainwindow v. 0.01</h2>\n"
"An application to help test various aspects of QT4\n"
"Thanks to anybody helping out :-)\n") );
}
void Mainwindow::createActions()
{
aboutAction = new QAction(tr("&About"), this);
connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) );
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_Main.h"
{
Q_OBJECT
public:
protected:
private slots:
void createActions();
void about();
private:
Ui::MainWindow ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_Main.h"
class QAction;
class QTextEdit;
class QMenu;
class Mainwindow : public QMainWindow
{
Q_OBJECT
public:
Mainwindow( QWidget *parent = 0 );
protected:
private slots:
void createActions();
void about();
private:
QAction *aboutAction;
Ui::MainWindow ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "Mainwindow.h"
int main( int argc, char **argv )
{
(new Mainwindow)->show();
return app.exec();
}
#include <QApplication>
#include "Mainwindow.h"
int main( int argc, char **argv )
{
QApplication app( argc, argv );
(new Mainwindow)->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks