0

main.cpp

#include <QtGui>
#include <QApplication>


int main(int argv, char **args)
{
    QApplication app(argv, args);

    QTextEdit textEdit;
    QPushButton quitButton("Quit");

    QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));

    QVBoxLayout layout;
    layout.addWidget(&textEdit);
    layout.addWidget(&quitButton);

    QWidget window;
    window.setLayout(&layout);
    window.show();

    return app.exec();        
}

notepad.cpp

#include <QtGui>
#include <QApplication>

class Notepad : public QMainWindow
{


    Notepad::Notepad()
    {
        saveAction = 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"));
    }
    Q_OBJECT

public:
    Notepad();

    private slots:
        void open();
        void save();
        void quit();

private:
    QTextEdit *textEdit;

    QAction *openAction;
    QAction *saveAction;
    QAction *exitAction;

    QMenu *fileMenu;
};

ERRORS:

extra qualification 'NotePad::' on Member Notepad (Line 8)

notepad::notepad() cannot be overloaded (Line 32)

with notepad::notepad (line 8)

Why am I getting these errors? The constructor looks fine and the class setup looks fine. But I am getting these errors.

Bart
  • 19,692
  • 7
  • 68
  • 77
Vladamier
  • 3
  • 2

2 Answers2

2

The Notepad:: in front of your Notepad() constructor inside the Notepad class is not necessary. Neither is the later declaration, because you have done this and defined it (although privately) above. You might want to consider separating it into a header and cpp file.

There are still various other issues with the code as you have posted, but the errors you posted are most likely caused by what I mentioned above.

Bart
  • 19,692
  • 7
  • 68
  • 77
1
  • You have qualified the inline private constructor with Notepad::
  • You have then incorrectly overloaded that private constructor as public in a second declaration
  • Q_OBJECT macro needs to be first in the class declaration before methods and members.
  • You have at least 4 memory leaks for each instance of Notepad?
  • etc

Perhaps pick up a book?

AJG85
  • 15,849
  • 13
  • 42
  • 50
  • The Code is in the tutorial for QT, so I don't know how their are so many internal errors http://doc.qt.nokia.com/4.7/gettingstartedqt.html#learn-more – Vladamier Aug 06 '11 at 00:00
  • 1
    I don't know if those classes take ownership of heap allocated objects so there may not be memory leaks but the tutorial has split up the notepad class into header and implementation files and has the `Q_OBJECT` macro in the right place. Your errors may mostly be related to copy & pasting without understanding thus the book recommendation. – AJG85 Aug 06 '11 at 00:04
  • 1
    Yes, in Qt most classes will take ownership. @Vladamier Besides the book recommendation by AJG85 I would also recommend having a look at the [Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Something free like the "Thinking in C++" books will really help you. – Bart Aug 06 '11 at 00:08
  • Thank you guys I will take your advice to heart. – Vladamier Aug 06 '11 at 00:12