I have a basic window that has a slot fileNew()
. When I run my app, I get the following error:
QObject::connect: No such slot QMainWindow::fileNew()
Why is it not finding the slot?
SdiWindow.h
class SdiWindow : public QMainWindow
{
public:
SdiWindow(QWidget * parent = 0);
private slots:
void fileNew();
private:
QTextEdit * docWidget;
QAction * newAction;
void createActions();
void createMenus();
};
SdiWindow.cpp
SdiWindow::SdiWindow(QWidget * parent) : QMainWindow(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle( QString("%1[*] - %2").arg("unnamed").arg("SDI") );
docWidget = new QTextEdit(this);
setCentralWidget(docWidget);
connect(
docWidget->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool))
);
createActions();
createMenus();
statusBar()->showMessage("Done");
}
void SdiWindow::createActions()
{
newAction = new QAction( QIcon(":/images/new.png"), tr("&New"), this );
newAction->setShortcut( tr("Ctrl+N") );
newAction->setStatusTip( tr("Create a new document") );
connect(newAction, SIGNAL(triggered()), this, SLOT(fileNew()));
}
void SdiWindow::createMenus()
{
QMenu * menu = menuBar()->addMenu( tr("&File") );
menu->addAction(newAction);
}
void SdiWindow::fileNew()
{
(new SdiWindow())->show();
}