tags:

views:

346

answers:

3

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
+6  A: 

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

#include <QtGui/QtGui> 

instead, or if you prefer

#include <QtGui/QPushButton>
Dirk Eddelbuettel
Wow. I gotta go kick myself for forgetting this!
Mohit Deshpande
+3  A: 

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

Frank
A: 

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.

Robin