Results 1 to 7 of 7

Thread: Weird compile error

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Red face Weird compile error

    Hello again! I need hlp pls!

    I have include file globals.h and here is its contens:
    Qt Code:
    1. // globals.h
    2.  
    3. #ifndef GLOBALS_H
    4. #define GLOBALS_H
    5.  
    6. // qt includes
    7. #include <QtGlobal>
    8.  
    9. // scene rect coords
    10. static const qint16 minX=-300;
    11. static const qint16 minY=-300;
    12. static const qint16 maxX=300; // scene width
    13. static const qint16 maxY=300; // scene height
    14.  
    15. if (minX<=0) {
    16. static const qreal rCenterX=(maxX+minX)/2; // scente centre x
    17. } else {
    18. static const qreal rCenterX=(maxX-minX)/2; // scente centre x
    19. };
    20.  
    21. if (minY<=0) {
    22. static const qreal rCenterY=(maxY+minY)/2; // scente centre x
    23. } else {
    24. static const qreal rCenterY=(maxY-minY)/2; // scente centre x
    25. };
    26.  
    27. static const qreal rCirleMargin=20.0; // circle margin
    28. static const qreal rCircleRadius=maxX-rCenterX-rCirleMargin; // radius of circle
    29.  
    30. // geometric constants
    31. static const qreal pi=3.14159265358979323846264338327950288419716939937510; // pi constant
    32. static const qreal Pi=pi; // alias for pi
    33. static const quint8 iLoadTreshold=10; // icon load treshold
    34. static const qreal rFullCircle=360; // full circle has 360 degrees
    35. static const qreal rAngle=rFullCircle/iLoadTreshold; // merchandize icon appears every rAngle degrees on rotary
    36. // merchandize selector
    37.  
    38. #endif
    To copy to clipboard, switch view to plain text mode 

    If I include this file into project, I get following weird compiler errors:
    Qt Code:
    1. C:\Documents and Settings\markofr\workspace\eROS>make
    2. mingw32-make -f Makefile.Debug
    3. mingw32-make[1]: Entering directory `C:/Documents and Settings/markofr/workspace
    4. /eROS'
    5. c:\Qt\4.3.2\bin\uic.exe crosmainwindow.ui -o ui_crosmainwindow.h
    6. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
    7. DQT_DLL -DQT_SVG_LIB -DQT_SQL_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB
    8. -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\4.3.2\inclu
    9. de\QtCore" -I"..\..\..\..\Qt\4.3.2\include\QtCore" -I"..\..\..\..\Qt\4.3.2\inclu
    10. de\QtNetwork" -I"..\..\..\..\Qt\4.3.2\include\QtNetwork" -I"..\..\..\..\Qt\4.3.2
    11. \include\QtGui" -I"..\..\..\..\Qt\4.3.2\include\QtGui" -I"..\..\..\..\Qt\4.3.2\i
    12. nclude\QtOpenGL" -I"..\..\..\..\Qt\4.3.2\include\QtOpenGL" -I"..\..\..\..\Qt\4.3
    13. .2\include\QtSql" -I"..\..\..\..\Qt\4.3.2\include\QtSql" -I"..\..\..\..\Qt\4.3.2
    14. \include\QtSvg" -I"..\..\..\..\Qt\4.3.2\include\QtSvg" -I"..\..\..\..\Qt\4.3.2\i
    15. nclude" -I"c:\Qt\4.3.2\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\4.3.2
    16. \mkspecs\win32-g++" -o debug\CLens.o CLens.cpp
    17. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
    18. DQT_DLL -DQT_SVG_LIB -DQT_SQL_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB
    19. -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\4.3.2\inclu
    20. de\QtCore" -I"..\..\..\..\Qt\4.3.2\include\QtCore" -I"..\..\..\..\Qt\4.3.2\inclu
    21. de\QtNetwork" -I"..\..\..\..\Qt\4.3.2\include\QtNetwork" -I"..\..\..\..\Qt\4.3.2
    22. \include\QtGui" -I"..\..\..\..\Qt\4.3.2\include\QtGui" -I"..\..\..\..\Qt\4.3.2\i
    23. nclude\QtOpenGL" -I"..\..\..\..\Qt\4.3.2\include\QtOpenGL" -I"..\..\..\..\Qt\4.3
    24. .2\include\QtSql" -I"..\..\..\..\Qt\4.3.2\include\QtSql" -I"..\..\..\..\Qt\4.3.2
    25. \include\QtSvg" -I"..\..\..\..\Qt\4.3.2\include\QtSvg" -I"..\..\..\..\Qt\4.3.2\i
    26. nclude" -I"c:\Qt\4.3.2\include\ActiveQt" -I"debug" -I"." -I"..\..\..\..\Qt\4.3.2
    27. \mkspecs\win32-g++" -o debug\cdatabasefoundation.o cdatabasefoundation.cpp
    28. In file included from cdatabasefoundation.h:7,
    29. from cdatabasefoundation.cpp:1:
    30. globals.h:15: error: expected unqualified-id before "if"
    31. globals.h:15: error: expected `,' or `;' before "if"
    32. globals.h:17: error: expected unqualified-id before "else"
    33. globals.h:17: error: expected `,' or `;' before "else"
    34. globals.h:21: error: expected unqualified-id before "if"
    35. globals.h:21: error: expected `,' or `;' before "if"
    36. globals.h:23: error: expected unqualified-id before "else"
    37. globals.h:23: error: expected `,' or `;' before "else"
    38. globals.h:28: error: `rCenterX' was not declared in this scope
    39. cdatabasefoundation.cpp:38:2: warning: no newline at end of file
    40. mingw32-make[1]: *** [debug\cdatabasefoundation.o] Error 1
    41. mingw32-make[1]: Leaving directory `C:/Documents and Settings/markofr/workspace/
    42. eROS'
    43. mingw32-make: *** [debug] Error 2
    To copy to clipboard, switch view to plain text mode 

    Wtf????
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird compile error

    You can't put any statements outside functions. If you really need this, use preprocessor directives and macros instead.

    Edit: Actually you don't need those if statements. The formula for the center is: center = (max + min) / 2, regardless if min is positive or not.
    Last edited by jacek; 3rd December 2007 at 16:52.

  3. #3
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird compile error

    the error is pretty clear: rCenterX is not decared in the scope

    explanation:
    you have declared rCenterX inside the brakes of the if statement. it's only valid inside .

  4. #4
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird compile error

    Quote Originally Posted by jacek View Post
    You can't put any statements outside functions.
    Yes - and that as well ;-)

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Weird compile error

    Ok, I see, sorry for stupid question. I am a little rusty at c++. Can you:
    1) Please move this thread to c++, siince it has no connection with qt
    2) How can I make macro, that will compute CenterX and CenterY?
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird compile error

    2)
    Qt Code:
    1. #define CENTER(x1, x2) ((x1+x2)/2)
    To copy to clipboard, switch view to plain text mode 
    That should do it.
    You can pass x or (-x) for the second param.

    OR, better yet:
    Qt Code:
    1. #define CENTER(x1,x2,result) {if (x2<=0){result=(x1+x2)/2;}else{result=(x1-x2)/2;}}
    To copy to clipboard, switch view to plain text mode 
    This one should be easier to use.
    Last edited by marcel; 3rd December 2007 at 18:19.

  7. The following user says thank you to marcel for this useful post:

    MarkoSan (3rd December 2007)

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird compile error

    Quote Originally Posted by MarkoSan View Post
    How can I make macro, that will compute CenterX and CenterY?
    First of all your original formula is wrong --- you don't need the if statement.

    When I have mentioned the macros, I wanted to say that if you want to have an if statement outside any function, you have to use #if directive instead. Since it doesn't work with variables, you need macros too.

    The problem is that macros are Bad. If you want something that calculates CenterX and CenterY, use inline functions.

  9. The following user says thank you to jacek for this useful post:

    MarkoSan (3rd December 2007)

Similar Threads

  1. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  2. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  3. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  4. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.