Results 1 to 4 of 4

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [SOLVED] Qt example not working " expected class-name before '{' token"

    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)
    Qt Code:
    1. #ifndef EXCEPTION_H
    2. #define EXCEPTION_H
    3.  
    4. #include <qtconcurrentexception.h>
    5. #include <QString>
    6.  
    7.  
    8. class Exception : public QtConcurrent::Exception {
    9.  
    10. // member declarations
    11. }
    To copy to clipboard, switch view to plain text mode 

    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??
    Last edited by davidmmx; 26th April 2009 at 18:54.

  2. #2
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt example not working " expected class-name before '{' token"

    Try to add a line:
    Qt Code:
    1. #include <QtConcurrent>
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt example not working " expected class-name before '{' token"

    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

    Qt Code:
    1. #ifndef QTCONCURRENT_EXCEPTION_H
    2. #define QTCONCURRENT_EXCEPTION_H
    3.  
    4. #include <QtCore/qglobal.h>
    5.  
    6. #ifndef QT_NO_QFUTURE
    7.  
    8. #include <QtCore/qatomic.h>
    9.  
    10. #ifndef QT_NO_EXCEPTIONS
    11. # include <exception>
    12. #endif
    13.  
    14. QT_BEGIN_HEADER
    15. QT_BEGIN_NAMESPACE
    16.  
    17. QT_MODULE(Core)
    18.  
    19. namespace QtConcurrent
    20. {
    21.  
    22. #ifndef QT_NO_EXCEPTIONS
    23.  
    24. class Q_CORE_EXPORT Exception : public std::exception
    25. {
    26. public:
    27. virtual void raise() const;
    28. virtual Exception *clone() const;
    29. };
    To copy to clipboard, switch view to plain text mode 

    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?

  4. #4
    Join Date
    Apr 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt example not working " expected class-name before '{' token"

    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

Similar Threads

  1. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 08:57
  2. Need help integrating sigc++ with a KDE3/Qt3 app
    By Valheru in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2007, 16:39
  3. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 21:09
  4. Replies: 2
    Last Post: 4th May 2006, 20:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.