PDA

View Full Version : Problem with conflicting defines



AndresBarbaRoja
23rd May 2011, 14:00
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:


#if defined(Q_WS_X11)
QApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0, int = QT_VERSION);
QApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0, int = QT_VERSION);
#endif

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

mcosta
23rd May 2011, 14:05
Try undefining HANDLE just before include QApplication like



#ifdef HANDLE
#undef HANDLE
#endif // HANDLE

#include <QApplication>

cincirin
23rd May 2011, 14:20
Try to avoid includes both card library headers and Qt headers in the same source file.

AndresBarbaRoja
23rd May 2011, 15:29
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.

Santosh Reddy
23rd May 2011, 19:43
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.



//libraryinterface.h

#ifdef LIBRARYINTERFACE_H
#define LIBRARYINTERFACE_H

#include <libraryname.h>

#ifdef HANDLE
#undef HANDLE
#define LIB_HANDLE int
#endif

#endif //LIBRARYINTERFACE


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