Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Having problem with Notepad app?

    General and Desktop
    3
    4
    1802
    Loading More Posts
    • 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
      saobien39 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_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 Reply Quote 0
      • S
        Sam 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
        }@

        1 Reply Last reply Reply Quote 0
        • S
          saobien39 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 ...

          1 Reply Last reply Reply Quote 0
          • G
            goetz 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.

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post