Results 1 to 15 of 15

Thread: Cannot #include some classes

  1. #1
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Cannot #include some classes

    I am moving a little app I have written from QT3 to QT4 (debian 4.4.5.3). When I inlcude some classes, like QListview and QComboBox, I get compilation errors. Just the #include line is enough to get these errors, no need to actually do something with the included class. Here is what I get when I include QListview:

    In file included from /usr/include/qt4/QtGui/qabstractitemdelegate.h:46,
    from /usr/include/qt4/QtGui/qabstractitemview.h:48,
    from /usr/include/qt4/QtGui/qlistview.h:45,
    from /usr/include/qt4/QtGui/QListView:1,
    from src/qm_tracks.h:41,
    from src/qm_player.h:52,
    from src/qm_core.h:27,
    from src/main.cpp:23:
    /usr/include/qt4/QtGui/qstyleoption.h:139: error: expected identifier before numeric constant
    /usr/include/qt4/QtGui/qstyleoption.h:139: error: expected '}' before numeric constant
    /usr/include/qt4/QtGui/qstyleoption.h:139: error: expected unqualified-id before numeric constant
    /usr/include/qt4/QtGui/qstyleoption.h:142: error: 'FrameFeature' was not declared in this scope
    /usr/include/qt4/QtGui/qstyleoption.h:142: error: template argument 1 is invalid
    /usr/include/qt4/QtGui/qstyleoption.h:142: error: invalid type in declaration before ';' token
    /usr/include/qt4/QtGui/qstyleoption.h:145: error: expected unqualified-id before ')' token
    /usr/include/qt4/QtGui/qstyleoption.h:146: error: expected unqualified-id before 'const'
    /usr/include/qt4/QtGui/qstyleoption.h:146: error: expected ')' before 'const'
    /usr/include/qt4/QtGui/qstyleoption.h:147: error: expected unqualified-id before 'const'
    /usr/include/qt4/QtGui/qstyleoption.h:147: error: expected ')' before 'const'
    etc.
    etc.

    Perhaps a required dependency is missing? Debian should have said so...

    Any ideas?

    Thanks in advance.

    Jayes.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Cannot #include some classes

    What is the content of these files at the mentioned lines?

    from src/qm_tracks.h:41,
    from src/qm_player.h:52,
    from src/qm_core.h:27,
    from src/main.cpp:23:

    Is it just the include line?

  3. #3
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by Lykurg View Post
    What is the content of these files at the mentioned lines?
    Is it just the include line?
    Yes, that's just one file including the next. Finally qm_tracks.h includes the qt class that is acting up.

    --
    jayes

  4. #4
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Cannot #include some classes

    Did you have modules added in project files? In your .Pro file you would have something like this:-

    Qt Code:
    1. QT += gui core
    To copy to clipboard, switch view to plain text mode 

    or you can check in your project properties if you have:-

    Qt Code:
    1. qt\4.4.5.3\include\QtGui
    2. qt\4.4.5.3\include\QtCore
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by user_mail07 View Post
    Did you have modules added in project files?
    Yes, I have:

    QT = core gui

    --
    jayes

  6. #6
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Cannot #include some classes

    Can you post some sample application code or example code to reproduce that problem. It has something to do with you with your project dependency. Try to just post .pro file and included header files.

  7. #7
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Here's my WAG:

    Line 139 in qstyleoption.h is:
    Qt Code:
    1. None = 0x00,
    To copy to clipboard, switch view to plain text mode 
    Do you have a "#define None 0" in one of the Quimup headers?

  8. #8
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by norobro View Post
    Do you have a "#define None 0" in one of the Quimup headers?
    Yes, I have the same Line 139 in qstyleoption.h

    For every class that acts up the errors are always the same (in qstyleoption.h).
    I searched a little more and came up with an old hack that fixes the problem:

    (see http://www.voxforge.org/home/forums/...tion-suite-gpl)

    In qstyleoption.h line 112+, insert:
    #ifdef None
    #undef None
    #endif

    This does indeed take care of the problems.

    What bothers me now is the fact that I have no idea what is fixed exactly... and this hack dates back to 2007! This should have been fixed by now.

    --
    jayes

  9. #9
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by norobro View Post
    ]Do you have a "#define None 0" in one of the Quimup headers?
    Hang on... I now see what you were asking!

    No, I don't have a "#define None 0" in any of my headers. And this looks like it has everything to do with the hack I described.

    Is "#define None 0" required for qt4 apps?

    .. and thanks for helping me out.

    --
    jayes

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot #include some classes

    Try reordering include entries in main.cpp. Could you paste the contents of that file (the includes section actually) here?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by wysota View Post
    Try reordering include entries in main.cpp.
    I doubt if that iwould make any difference. Whatever the order, when the errors occur those includes have all been included.

    Nevertheless, here you are:

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "qm_core.h"
    3.  
    4. int main( int argc, char ** argv )
    5. {
    6. QApplication app(argc, argv);
    7. qm_core core;
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    qm_core.h
    Qt Code:
    1. #include <QMainWindow>
    2. #include "qm_player.h"
    3.  
    4. class qm_core : public QMainWindow
    5. {
    6. Q_OBJECT
    7. public:
    8. qm_core();
    9. virtual ~qm_core();
    10.  
    11. private:
    12. qm_player player;
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 

    qm_player.h
    Qt Code:
    1. #include <QMainWindow>
    2. #include <QApplication>
    3. #include <QCloseEvent>
    4. #include <QFrame>
    5. #include <QLabel>
    6. #include <QPushButton>
    7. #include <QSlider>
    8. #include <QImage>
    9. #include <QPixmap>
    10. #include <QSettings>
    11. #include <QTimer>
    12. #include <QSignalMapper>
    13. #include <QPalette>
    14. #include <QDir>
    15. #include <QProcess>
    16. #include <QVBoxLayout>
    17. #include <QMenu>
    18. #include <stdlib.h>
    19. #include "libmpdclient.h"
    20. #include "qm_clicklabel.h"
    21. #include "qm_clickprogressbar.h"
    22. #include "qm_config.h"
    23. #include "qm_mpdcom.h"
    24. #include "qm_trayicon.h"
    25. #include "qm_widget_ids.h"
    26. #include "qm_scroller.h"
    27. #include "qm_settings.h"
    28. #include "qm_tracks.h"
    To copy to clipboard, switch view to plain text mode 

    finally: qm_tracks.h
    Qt Code:
    1. #include <QMainWindow>
    2. #include <QApplication>
    3. #include <QWidget>
    4. #include <QButtonGroup>
    5. #include <QCheckBox>
    6. #include <QFrame>
    7. #include <QVariant>
    8. #include <QAction>
    9. #include <QGridLayout>
    10. #include <QHBoxLayout>
    11. #include <QVBoxLayout>
    12. #include <QGroupBox>
    13. #include <QLabel>
    14. #include <QLineEdit>
    15. #include <QPushButton>
    16. #include <QSpacerItem>
    17. #include <QSplitter>
    18. #include <QList>
    19. #include <QPixmap>
    20. #include <QTabWidget>
    21. #include <QTimer>
    22. #include <QListView>
    23. #include <QComboBox>
    24. #include <QCloseEvent> (etc.)
    To copy to clipboard, switch view to plain text mode 

    PS. I intercept the CloseEvent in qm_player, which would prevent KDE from shutting down if the player was the top window. That's why I made it a sibling of the 'fake' window called qm_core.

    --
    jayes

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot #include some classes

    Quote Originally Posted by Jayes View Post
    I doubt if that iwould make any difference. Whatever the order, when the errors occur those includes have all been included.
    It does make a difference. Consider the following example:

    Qt Code:
    1. // file1.h
    2. #ifndef X
    3. #define X int
    4. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // file2.h
    2. #ifndef X
    3. #define X std::string
    4. #endif
    To copy to clipboard, switch view to plain text mode 
    and then two orders of inclusion:
    Qt Code:
    1. // main.cpp
    2. #include "file1.h"
    3. #include "file2.h"
    4. //...
    5. X x;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // main.cpp
    2. #include "file2.h"
    3. #include "file1.h"
    4. // ...
    5. X x;
    To copy to clipboard, switch view to plain text mode 
    Now in version 1 "x" will be of type "int" but in version 2 it will be of type "std::string". So the order may matter (in a place AFTER the files have been included - when "x" is declared).

    Try reordering the includes and try to substitute all the includes you can with forward declarations.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    norobro (13th March 2010)

  14. #13
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Quote Originally Posted by wysota View Post
    Try reordering the includes and try to substitute all the includes you can with forward declarations.
    Wysota, you are not just a master of Zen...

    I tried many permutations and found that, in qm_player.h

    this does not workt:

    #include "qm_config.h"
    #include "qm_tracks.h"

    and this works fine:

    #include "qm_tracks.h"
    #include "qm_config.h"

    The culprit is

    #include <X11/Xlib.h>

    in qm_config.h. It is something I can do without, so I removed it. Now I can put qm_tracks.h where I please.

    Well, I learned something today. Thank you very much indeed!

    --
    jayes

  15. #14
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Cannot #include some classes

    Jayes,

    I didn't think that the include order of header files made any difference either. Wysota's explanation cleared that up for me. Anyway I was browsing around in the sources and found this in qcoreevent.h:
    Qt Code:
    1. enum Type {
    2. /*
    3.   If you get a strange compiler error on the line with None,
    4.   it's probably because you're also including X11 headers,
    5.   which #define the symbol None. Put the X11 includes after
    6.   the Qt includes to solve this problem.
    7.   */
    8. None = 0, // invalid event
    To copy to clipboard, switch view to plain text mode 
    It would have been nice if that comment was in qstyleoption.h, huh?
    Norm

  16. #15
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cannot #include some classes

    IMO, It's just another reason why you should never have such ambiguous symbols in your code base. I dislike code which is like this (Although I don't avoid such code unless it's small or easily rewritten). Either put the enum in a class, or prefix it with the subsystem its involved with. Eg. if "None" is associated with the event code, then it should be named "QtEvent_None".

Similar Threads

  1. how to make include in qt
    By nataly in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2009, 16:39
  2. Include issue
    By Platoon in forum Newbie
    Replies: 2
    Last Post: 6th October 2009, 10:28
  3. mfc in QT include
    By trusch in forum Qt Programming
    Replies: 3
    Last Post: 16th July 2009, 10:01
  4. #include <QBean>... what's it mean?
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2007, 06:55
  5. include
    By mickey in forum Newbie
    Replies: 6
    Last Post: 4th April 2006, 23:14

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.