Results 1 to 15 of 15

Thread: Cannot #include some classes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    norobro (13th March 2010)

  3. #2
    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

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

    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

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

    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
  •  
Qt is a trademark of The Qt Company.