Mohit Deshpande
Mohit Deshpande

Reputation: 55237

ISO C++ forbids declaration of 'QPushButton' with no type in QT Creator

I am running QT Creator on a Linux Ubuntu 9.10 machine. I just got started with QT Creator, and I was going through the tutorials when this error popped up while I was trying to build my project: "ISO C++ forbids declaration of 'QPushButton' with no type". This problem appears in my header file:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QWidget>

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void addContact();
    void submitContact();
    void cancel();

private:
    Ui::MainWindow *ui;
    QPushButton *addButton;
    QPushButton *submitButton;
    QPushButton *cancelButton;
    QLineEdit *nameLine;
    QTextEdit *addressText;

    QMap<QString, QString> contacts;
    QString oldName;
    QString oldAddress;


};
#endif // MAINWINDOW_H

Upvotes: 3

Views: 4299

Answers (4)

malhobayyeb
malhobayyeb

Reputation: 2881

You are missing this:

#include <QtGui>

Upvotes: 1

Robin
Robin

Reputation: 1698

You might also want to check the .pro file.
Do you have an entry like "QT = ..." somewhere? If so, try changing that to "QT += ...". Qt's Core and GUI module are default settings for the QT variable, but CAN be overwritten, which will lead to compiler and/or linker errors.

Upvotes: 0

Frank Osterfeld
Frank Osterfeld

Reputation: 25165

Actually, forward declaration would be enough, instead of the include:

class QPushButton;

Always prefer forward declarations in headers, and do the include in the .cpp (faster and less recompilations in larger projects).

Upvotes: 5

Dirk is no longer here
Dirk is no longer here

Reputation: 368389

I think you are simply missing the appropriate header file. Can you try

#include <QtGui/QtGui> 

instead, or if you prefer

#include <QtGui/QPushButton>

Upvotes: 7

Related Questions