Vladamier
Vladamier

Reputation: 3

Some Problems with Qt (C++)

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.

Upvotes: 0

Views: 1375

Answers (2)

AJG85
AJG85

Reputation: 16217

  • 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?

Upvotes: 1

Bart
Bart

Reputation: 20048

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.

Upvotes: 2

Related Questions