PDA

View Full Version : [SOLVED] Qt example not working " expected class-name before '{' token"



davidmmx
26th April 2009, 14:15
Hi, I've just started to read about Qt, so I bought a book and downloaded a library to be used with the examples. When I try to compile that library I get the error of the class name. I've had a look at the code but didn't see anything wrong.

The error:


make[1]: se ingresa al directorio `/mnt/almacen/dev-libs/utils'
g++ -c -pipe -march=athlon64 -O2 -pipe -march=athlon64 -O2 -Wall -W -D_REENTRANT -fPIC -DLIBRARY_BUILD -D__PWD__=/home/whisp/almacen/dev-libs/utils -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB
-DQT_SHARED -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.moc -I.ui -o .obj/exception.o exception.cpp
In file included from exception.cpp:1:
exception.h:8: error: expected class-name before '{' token
make[1]: *** [.obj/exception.o] Error 1



and the code from exception.h until the line of the error (not my code, as I've said before)


#ifndef EXCEPTION_H
#define EXCEPTION_H

#include <qtconcurrentexception.h>
#include <QString>


class Exception : public QtConcurrent::Exception {

// member declarations
}



I know this kind of error would have been caused by a typo in the classname, or if the class hadn't been declared, but it's declared in qtconcurrentexception.h , and in the QtConcurrentNamespace, so... what's wrong??

roxton
26th April 2009, 17:23
Try to add a line:


#include <QtConcurrent>

davidmmx
26th April 2009, 17:46
Thanks a lot for taking the time to answer. Unfortunately it doesn't work.
The new error "exception.h:6:24: error: QtConcurrent: No existe el fichero o el directorio" says there is no such file or directory.

Just a quick search:


find /usr/include/ -name "*QtConcurrent*"
/usr/include/qt4/QtCore/QtConcurrentMap
/usr/include/qt4/QtCore/QtConcurrentRun
/usr/include/qt4/QtCore/QtConcurrentFilter

The output is this:


make[1]: se ingresa al directorio `/mnt/almacen/dev-libs/utils'
g++ -c -pipe -march=athlon64 -O2 -pipe -march=athlon64 -O2 -Wall -W -D_REENTRANT -fPIC -DLIBRARY_BUILD -D__PWD__=/home/whisp/almacen/dev-libs/utils -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -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.moc -I.ui -o .obj/exception.o exception.cpp
En el fichero incluÃ*do de exception.cpp:1:
exception.h:6:24: error: QtConcurrent: No existe el fichero o el directorio
In file included from exception.cpp:1:
exception.h:9: error: expected class-name before '{' token
make[1]: *** [.obj/exception.o] Error 1
make[1]: se sale del directorio `/mnt/almacen/dev-libs/utils'
make: *** [sub-utils-make_default] Error 2



I've tried with #include <QtCore> too, which I think should import the QtConcurrent namespace too, with the same outcome.

Just to be more precise, in qtconcurrentexception.h is the declaration of QtConcurrent::Exception



#ifndef QTCONCURRENT_EXCEPTION_H
#define QTCONCURRENT_EXCEPTION_H

#include <QtCore/qglobal.h>

#ifndef QT_NO_QFUTURE

#include <QtCore/qatomic.h>

#ifndef QT_NO_EXCEPTIONS
# include <exception>
#endif

QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE

QT_MODULE(Core)

namespace QtConcurrent
{

#ifndef QT_NO_EXCEPTIONS

class Q_CORE_EXPORT Exception : public std::exception
{
public:
virtual void raise() const;
virtual Exception *clone() const;
};


but I don't know anything about the macros that appear before QtConcurrent::Exception and may have something to do with this.

Could I post the URL of the example, or would it be considered spam?

davidmmx
26th April 2009, 17:54
Ok, someone just told me to add

CONFIG += exceptions

to the .pro file... strange because as an example it was supposed to be ready to be compiled... I'm having other problems like this but I assume I'll be able to solve them messing with the .pro file.

Thanks for your time