tags:

views:

147

answers:

2

I'm running "QUdpSocket::ShareAddress" on my QT application but ShareAddress is ignored by windows. So I'm trying to solve this problem by identifying OS at run time. I heard a couple of information about window version indentifier but I couldn't see any solution to solve my problem. If there is any of advice, it would be very appreciated. Thanks.

+10  A: 
#include <QtGlobal>
...
#ifdef Q_OS_MAC
// mac
#endif

#ifdef Q_OS_LINUX
// linux
#endif

#ifdef Q_OS_WIN32
// win
#endif

See QtGlobal documentation for further information.

kemiisto
Thanks for your help. I'll try it right now.
KIM
It does work. I found items for C++ also. Thanks.
KIM
+1  A: 

It isn't always the most elegant solution, but it's definitely effective to use a preprocessor definition to check platform at compile time.

Example:

#ifdef _WIN32
#endif
Drakonite
Thanks for your advice. Isn't _WIN32 for QT but C++?
KIM
Yes,it is not Qt specific defines. You can get list of them at http://predef.sourceforge.net/preos.html
kemiisto
Yeah, there was. Thanks for your help.
KIM