Proper way of testing whether Qt is being used by a program
I have a small library which I would like to be used with both Qt and non-Qt programs. Basically I want to use QList if the calling program will be using Qt anyway, else I want to use std::list. So I am thinking of using #define-s like:
Code:
#ifdef QT_VERSION
#define MYLIST QList
#else
#include <list>
#define MYLIST std::list
#endif
... and then use MYLIST throughout my code. I think it is safe to assume for practical purposes that if QT_VERSION is defined, Qt is being used? Is this OK? I want to know what is the accepted/conventional of testing whether Qt is being used.
In relation, if a program uses Qt, does it mean it also uses std::list anyway? I'm asking since QList seems to have facilities to convert to and from std::list which may not be possible if std::list is not used somewhere inside Qt?
Re: Proper way of testing whether Qt is being used by a program
QList is not a wrapper around std::list, QString is not a glorified std::string wrapper etc. Qt applications can be built with some support for conversion to/from STL types. However, if Qt is compiled with the "-no-stl" configure option then the Qt to STL functions will not be present. At compile time this is seen as a defined QT_NO_STL.
Even with STL support, the Qt containers are not 100% interchangeable with their STL counterparts: no reverse STL-style iterator on a QList for example. Just substituting QList for std::list may not work.
Re: Proper way of testing whether Qt is being used by a program
Hello and thanks for reminding me of the difference in API between QList and std::list etc. I am perfectly aware of it though. Obviously I'd only be using whatever is common between the two.
If you have an answer to my actual question I'd appreciate that. Thanks.