Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, August 2007
error: ISO C++ forbids declaration of 'QLabel' with no type


Message 1 in thread

Hi:

If you look at the compiler output, below, you will see a 
"finddilog.h:47" error. I can't seem to locate the problem.  The code 
was copied, verbatim, from the C++ GUI Programming with Qt4 book by 
Blanchette and Summerfield.

I am working on a Linux, Debian Etch system. While I use the Gnome X11 
desktop, I am using KDevelop for  project management software. (a 
really, really nice environment to work in). I have KDevelop setup for 
using Qt and qmake compiler system. On the first programs I compiled, 
everything worked fine. This one doesn't. HELP!


COMPILER OUTPUT------------------------------------------------
cd '/home/gary/projects/testing' && make -k
cd src/ && make -f Makefile
g++ -c -pipe -g -D_REENTRANT -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB 
-I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore 
-I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui 
-I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o moc_finddialog.o 
moc_finddialog.cpp
finddialog.h:47: error: ISO C++ forbids declaration of 'QLabel' with no type
finddialog.h:47: error: expected ';' before '*' token
make[1]: *** [moc_finddialog.o] Error 1
make[1]: Target `first' not remade because of errors.
<br />
make: *** [sub-src-make_default] Error 2
make: Target `first' not remade because of errors.
*** Exited with status: 2 ***

MAIN.CPP------------------------------------------------------------------

#include <QApplication>

int main(int argc, char *argv[])
{
      Q_INIT_RESOURCE(application);
      QApplication app(argc, argv);
//      finddialog * mw = new finddialog();
//      mw->show();
      return app.exec();
}


FINDDIALOG.H------------------------------------------------------------
#ifndef FINDDIALOG_H
#define FINDDIALOG_H

#include <QDialog>

class QCheckBox;
class QLable;
class QLineEdit;
class QPushButton;

class FindDialog : public QDialog
{
    Q_OBJECT 
           
    public:
        FindDialog(QWidget *parent =0);
       
    signals:
        void findNext(const QString &str, Qt::CaseSensitivity cs);
        void findPrevious(const QString &str, Qt::CaseSensitivity cs);
       
    private slots:
        void findClicked();
        void enableFindButton(const QString &text);
       
    private:
        QLabel *label;
        QLineEdit *lineEdit;
        QCheckBox *caseCheckBox;
        QCheckBox *backwardCheckBox;
        QPushButton *findButton;
        QPushButton *closeButton;
       
};
#endif


FINDDIALOG.CPP---------------------------------------------------------

#include <QtGui>
#include "finddialog.h"

FindDialog::FindDialog(QWidget *parent)
    : QDialog(parent)
{
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);
   
    caseCheckBox = new QCheckBox(tr("Match &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));
   
    findButton = new QPushButton(tr("&Find"));
    findButton->setDefault(true);
    findButton->setEnabled(false);
   
    closeButton = new QPushButton(tr("Close"));
   
    connect(lineEdit, SIGNAL(textChanged(const QString &)),
        this,     SLOT(enableFindButton(const QString &)));
    connect(findButton, SIGNAL(clicked()),
        this, SLOT(findClicked()));
    connect(closeButton, SIGNAL(clicked()),
        this, SLOT(close()));
   
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);
    topLeftLayout->addWidget(lineEdit);
   
    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);
    leftLayout->addWidget(caseCheckBox);
    leftLayout->addWidget(backwardCheckBox);
   
    QVBoxLayout *rightLayout = new QVBoxLayout;
    rightLayout->addWidget(findButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();
   
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
   
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
}

SRC.PRO------------------------------------------------------------------------
SOURCES += main.cpp \
           finddialog.cpp
TEMPLATE = app
CONFIG += warn_on \
      thread \
          qt4
TARGET = ../bin/testing
RESOURCES = application.qrc
HEADERS += finddialog.h

_____________________________________
GaryR


Message 2 in thread

On August 30, 2007 04:57:41 pm Gary L. Roach wrote:
> class QLable;

Should be:
class QLabel;

I think that's your only mistake.

--
 [ signature omitted ] 

Message 3 in thread

On 30.08.07 15:57:41, Gary L. Roach wrote:
> If you look at the compiler output, below, you will see a "finddilog.h:47" 
> error. I can't seem to locate the problem.  The code was copied, verbatim, from 
> the C++ GUI Programming with Qt4 book by Blanchette and Summerfield.

I doubt that you copied that verbatim ;)

> class QLable;

There's a typo here.

>        QLabel *label;

Which will cause an error here. Exactly how the compiler message says,
if the compiler complains about a type not being known check your
include's in that file and your forward declarations.
 
Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

Thanks for the help and the suggestions. Dumb mistakes are sometime the 
hardest to find.

GaryR
>   

--
 [ signature omitted ]