Originally Posted by
squidge
and the solution to fix that is in post #2
Actually its not as and doesn't use qmake.
So I figure out the moc thing just before I looked here as I tried building under QtCreator but now I am getting the following error (in both QtCreator and codeblocks):
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:74: undefined reference to `Notepad::open()'
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:75: undefined reference to `Notepad::save()'
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:76: undefined reference to `Notepad::quit()'
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:74: undefined reference to `Notepad::open()'
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:75: undefined reference to `Notepad::save()'
debug/moc_notepad.o:C:\programming\c\test\test-build-desktop/debug/moc_notepad.cpp:76: undefined reference to `Notepad::quit()'
To copy to clipboard, switch view to plain text mode
For completeness here is the entire code:
notepad.h
#ifndef _NOTEPAD_H_
#define _NOTEPAD_H_
#include <QtGui>
{
Q_OBJECT
public:
Notepad();
private slots:
void open();
void save();
void quit();
private:
QAction *openAction;
// For the widgets that perform open
QMenu *fileMenu;
// Holds the menu options };
#endif
#ifndef _NOTEPAD_H_
#define _NOTEPAD_H_
#include <QtGui>
class Notepad: public QMainWindow
{
Q_OBJECT
public:
Notepad();
private slots:
void open();
void save();
void quit();
private:
QTextEdit *textEdit; // The text editor
QAction *openAction; // For the widgets that perform open
QAction *saveAction; // Save shit
QAction *quitAction; // Quit shit
QMenu *fileMenu; // Holds the menu options
};
#endif
To copy to clipboard, switch view to plain text mode
notepad.cpp
#include "notepad.h"
Notepad::Notepad()
{
// Do the actions first
openAction
= new QAction(tr
("&Open"),
this);
saveAction
= new QAction(tr
("&Sace"),
this);
quitAction
= new QAction(tr
("E&xit"),
this);
// Now connect the signals to the actions
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
// Now set the menu bar
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(quitAction);
setCentralWidget(textEdit);
setWindowTitle(tr("Notepad"));
}
#include "notepad.h"
Notepad::Notepad()
{
// Do the actions first
openAction = new QAction(tr("&Open"), this);
saveAction = new QAction(tr("&Sace"), this);
quitAction = new QAction(tr("E&xit"), this);
// Now connect the signals to the actions
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
// Now set the menu bar
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addSeparator();
fileMenu->addAction(quitAction);
textEdit = new QTextEdit;
setCentralWidget(textEdit);
setWindowTitle(tr("Notepad"));
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "notepad.h"
int main(int argc, char ** argv)
{
Notepad notepad;
notepad.show();
return app.exec();
}
#include "notepad.h"
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
Notepad notepad;
notepad.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks