Strange error when is include new class. (MSVS 2010)



  • When I add a header file of my class then is happen this error:

    @1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2143: syntax error : missing ')' before 'constant'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2143: syntax error : missing ';' before 'constant'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2805: binary 'operator |' has too few parameters
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2059: syntax error : ')'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2143: syntax error : missing ';' before '{'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2447: '{' : missing function header (old-style formal list?)
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2143: syntax error : missing ')' before 'constant'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2143: syntax error : missing ';' before 'constant'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2059: syntax error : ')'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2059: syntax error : '}'
    1>d:\qt\4.8.0\include\qtcore../../src/corelib/kernel/qeventloop.h(95): error C2059: syntax error : '}'@

    When I into my primary Main Window class add this
    @#include "mynewclass.h"@

    If I comment this piece of code:
    @//#include "mynewclass.h"@

    Everything works fine.

    Class is usual C++ class (no QT) and in my test project works fine, so in class shouldn´t be error. I don´t understand this error and link between add new class and qeventloop…


  • Moderators

    Based on this information it is hard to give a sound advice.
    My assumption is that there is a define in your new header which is messing up a bit things.

    Are you including the new header at the very top respectively before includes of Qt headers?



  • Should I include header of my classes before include of QT header?

    Anyway you answer helped me – thank you. The mistake was in defined of constants. In my class I have lots of constants (like this: #define xy 1234) and it´s caused the error. Now I´m (thank to you) a little bit smarter. How you wrote probably some constant was define twice…


  • Moderators

    You are welcome.

    Personally I would place the Qt headers first. But this may vary with the actual implementation. The defines are typically causing such problems. You should review your code carefully.



  • If possible, you could change to true constants, instead of preprocessor macros.

    If you need to stick to macros, it's always a good idea to start the macro names with some prefix common to you project, so for example instead of just using NUMFILES, it would be better to use QTC_NUMFILES (if we assume coding for Qt Creator here). This way you have much better chances that it doesn't clash with some other #defines.



  • You´re right, real constants are maybe better idea. For now I added prefix.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.