Results 1 to 5 of 5

Thread: Problem with conflicting defines

  1. #1
    Join Date
    Mar 2011
    Posts
    23
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with conflicting defines

    Good day,
    I'm having a problem with the library of a card that defines "HANDLE" as int. Then in Qt, when I use QApplication on Linux I get a compilation problem because in qapplication.h on line 130 and 131 it says:
    Qt Code:
    1. #if defined(Q_WS_X11)
    2. QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = QT_VERSION);
    3. QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = QT_VERSION);
    4. #endif
    To copy to clipboard, switch view to plain text mode 
    and my guess is that in those lines handle is replaced by int.
    The thing is that i do not know how to fix this.
    If I modify qapplication in order to undefine HANDLE,will I guess I will have problems in any computer running the regular qt. Could anyone suggest something I could do?
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with conflicting defines

    Try undefining HANDLE just before include QApplication like

    Qt Code:
    1. #ifdef HANDLE
    2. #undef HANDLE
    3. #endif // HANDLE
    4.  
    5. #include <QApplication>
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    AndresBarbaRoja (23rd May 2011)

  4. #3
    Join Date
    Feb 2011
    Location
    Romania
    Posts
    53
    Thanks
    1
    Thanked 11 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with conflicting defines

    Try to avoid includes both card library headers and Qt headers in the same source file.

  5. #4
    Join Date
    Mar 2011
    Posts
    23
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with conflicting defines

    Ok, I undefined HANDLE as suggested and everything is ok, but when I try to use windows created with Qt Creator some includes of QApplication are automatically created. Any idea how to avoid that? because even if I correct by hand the files when I rebuild the changes are lost.

  6. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Problem with conflicting defines

    Assuming you library does not use Qt Libs. You can try create wrapper header file which looks somehting like this, and use this file is rest of project, never include the library file directly.

    Qt Code:
    1. //libraryinterface.h
    2.  
    3. #ifdef LIBRARYINTERFACE_H
    4. #define LIBRARYINTERFACE_H
    5.  
    6. #include <libraryname.h>
    7.  
    8. #ifdef HANDLE
    9. #undef HANDLE
    10. #define LIB_HANDLE int
    11. #endif
    12.  
    13. #endif //LIBRARYINTERFACE
    To copy to clipboard, switch view to plain text mode 

    now you can use LIB_HANDLE instead of HANDLE in your code which uses the library calls (if required at all)

Similar Threads

  1. Replies: 0
    Last Post: 3rd October 2010, 20:51
  2. Detect conflicting thread
    By giusepped in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2009, 02:16
  3. Conflicting header definitions
    By jacky in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2009, 09:51
  4. Qt causes conflicting function names
    By thomaspu in forum Qt Programming
    Replies: 6
    Last Post: 14th September 2007, 15:30
  5. Qt4 Preprocessor defines
    By Chicken Blood Machine in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 16:28

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.