Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Having problem with Notepad app?
Forum Updated to NodeBB v4.3 + New Features

Having problem with Notepad app?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saobien39
    wrote on 12 Jun 2012, 02:13 last edited by
    #1

    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_OBJECT

    public:
    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)!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on 12 Jun 2012, 04:15 last edited by
      #2

      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
      }@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        saobien39
        wrote on 12 Jun 2012, 05:40 last edited by
        #3

        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 ...

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 23 Jun 2012, 09:04 last edited by
          #4

          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.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved