Having problem with Notepad app?
-
wrote on 12 Jun 2012, 02:13 last edited by
Notepad app, sounds fantastic but it's so simple, I only have 3 files, I compile and getting some errors, somebody help me.
notepad.h
@
#ifndef NOTEPAD_H
#define NOTEPAD_H#include <QtGui>
class Notepad : public QMainWindow
{
Q_OBJECTpublic:
Notepad();private slots:
void open();
void save();
void quit();private:
QTextEdit *textEdit;
QAction *openAction;
QAction *saveAction;
QAction *exitAction;
QMenu *fileMenu;
};#endif
@notepad.cpp
@
#include "notepad.h"Notepad::Notepad()
{
openAction = new QAction(tr("&Open"), this);
saveAction = new QAction(tr("&Save"), this);
exitAction = new QAction(tr("E&xit"), this);connect(openAction, SIGNAL(triggered()), this, SLOT(open())); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); textEdit = new QTextEdit; setCentralWidget(textEdit); setWindowTitle(tr("Notepad"));
}
@main.cpp
@
#include <QtGui/QApplication>
#include "notepad.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Notepad *note = new Notepad;
note->show();
return a.exec();
}
@Its error:
!http://nn0.upanh.com/b5.s1.d4/eea0527fdf7b5b61c575404df5e51e17_46009170.h1.png(error)!
-
wrote on 12 Jun 2012, 04:15 last edited by
You have declared the three slots in notepad.h. You need to write the definition of the same in your implementation file i.e notepad.cpp
@
void Notepad::open()
{
//do something
}void Notepad::save()
{
//do something
}void Notepad::quit()
{
//do something
}@ -
wrote on 12 Jun 2012, 05:40 last edited by
oh, I will review it, thanks :)
ps:
@
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(exitAction, SIGNAL(triggered()), qApp , SLOT(quit()));
@I don't know how difference between this and qApp ...
-
wrote on 23 Jun 2012, 09:04 last edited by
this is a pointer to the object you are in - in this case it's the Notepad object. aApp is a convenience macro that returns a pointer to the QApplication object.
The recent docs with the "Getting started with Qt tutorial":/doc/qt-4.8/gettingstartedqt.html have some additions regarding the missing methods.