Unsolved Is there a #define for checking if the compiler is Qt?
-
@JonB said in Is there a #define for checking if the compiler is Qt?:
@kitfox
Sorry, I still don't think you're getting it. By the time you have a.pro
file to put anything in, you're already compiling for Qt, aren't you?No, you can build a Qt-less project.
@kitfox yes that's a define you have to enable yourself like shown in the Shared Library chapter of Qt's documentation.
-
@SGaist
Why would you start with a.pro
file if you don't have Qt anywhere? What are you going to process it with? -
@JonB do you mean if you don't use Qt in your project ? Maybe because you are used to use qmake to manage your projects and are satisfied with it.
-
@SGaist
I envisage the OP is asking: he gives all his code plus Makefiles to someone else, who may not possess Qt at all, noqmake
etc. And they can compile the code some other way with nothing Qt anywhere.Then at one point he said
either by clicking build within Qt Creator or by whatever compiler the original author was using.
So maybe he'd like to know if he's compiling from Qt Creator or not.
The point I'm trying to get across is he will need to define some symbol somewhere if he wants to compile for/with Qt or some symbol somewhere if he wants to compile otherwise.
QT_IS_AVAILABLE
has got to be defined somewhere in those cases where it's wanted, else it'll never any effect. Different makefiles, an environment variable, something so the Qt or non-Qt compilation can be performed. -
@kitfox What kind of modifications are you doing?
-
That's right. I'm having trouble thinking of a way to rewrite ffmpeg-cpp_global.h so that it would work either inside of outside of a Qt environment. Currently
FFMPEGCPP_LIBRARY
is defined in the .pro file and acts as a switch - if it's included, thenFFMPEGCPP_EXPORT
transforms into instructions to export the definition to a dll. However, if it's not included (which it presumably would not be to anyone who wanted to use the library) it turns into a declaration to import the definition - instructions which depend on the Qt API to work. So what am I supposed to use if someone it trying to compile this with another compiler? I'd like a way to essentially nullify everything in this header file if I can tell that the person trying to compile it is not using Qt.As far as I can tell, I'm going to have to have everyone using Qt who wants to use this library add some define in their .pro file so that the imports are generated. Ie, something like:
#ifdef IM_USING_QT #include <QtCore/qglobal.h> #if defined(FFMPEGCPP_LIBRARY) # define FFMPEGCPP_EXPORT Q_DECL_EXPORT #else # define FFMPEGCPP_EXPORT Q_DECL_IMPORT #endif #else #define FFMPEGCPP_EXPORT #endif
-
Just trying to get the library to build under Qt. Then would like to write a few simple apps to test it to make sure it's working.
-
@kitfox It would be nice if there were some equivalent of IM_USING_QT automatically defined so that I would not have to have all QT users explicitly specify it.
-
If you're using a decent compiler you can use __has_include to check if Qt headers are available and define some macro constant if they are.
That doesn't solve any linker and toolchain (moc etc.) issues, but that's how you can detect if Qt source is available in your project. -
@kitfox
If your definition of "I'm using Qt" is you have the Qt include files on your box, @Chris-Kawa's suggestion looks great. Is that what you wanted? Or did you say you wanted to know whether the user is sitting inside Qt Creator? Or does the user choose whether he wants to compile for Qt or not (e.g. like you will want to while testing each route of this code)? What exactly is the deciding factor? -
@kitfox why not use CMake so that you can specifically define whether or not to use Qt, and then decide which implementation source file to add to compilation?
-
If the user wants to compile with the Qt API using my modifications, I want the DLL import/export tags to resolve to the definitions defined in QtCore/qglobal.h. If they wish to use the original environment they were developed in, or some other non Qt environment, I would like the FFMPEGCPP_EXPORT tag to resolve to the empty string and the #include <QtCore/qglobal.h> left out so that they can compile with their libraries. Basically as this is an open source library, I'm trying to make minimal changes and leave it in a state such that it can still compile in its original environment, while also making it capable of compiling using the Qt environment.
-
I'm not familiar with cmake. I suppose I should learn it, but I haven't had the time.
-
Try
#if defined(QT_VERSION)
-
This post is deleted! -
@hskoglund
Where doesQT_VERSION
get defined, please? Isn't it via#include <QtGlobal>
, so it tells you whether or not you have already included that file? How do you decide whether to include that or not? That's the bit I don't get....@kitfox
OK, to be fair/clear, surrounding some Qt-only code in#if defined(QT_VERSION)
looks like a good model for most of your code. It's a clean symbol. So that's good.You still have to "get going" somewhere, to decide whether to define that or include
QtGlobal.h
or not in the first place. -
@JonB Yeah, I realized that after I made the last post. For now I'll add an extra define to my build file.
-
@kitfox
:) :) Which is what I've been trying to get at all along :) -
@JonB said in Is there a #define for checking if the compiler is Qt?:
Where does QT_VERSION get defined, please? Isn't it via #include <QtGlobal>, so it tells you whether or not you have already included that file? How do you decide whether to include that or not? That's the bit I don't get....
nope, its part of qmake, and the define is available inside the *.pro file therefore influencing the generated make file.
Its generally used to check if some features are available in the Qt version you're using or not, to therefore include specific files(or not)
-
@J-Hilk
Ah, now when I Googled yesterday I found a post (stackoverflow??) which said thatQT_VERSION
was defined inQtGlobal
. Admittedly I think the post was from years ago, but I often find Qt is behaving the same as at the turn of the millennium :) Ah, yes, see https://stackoverflow.com/a/24903583/489865. And that was as recent as 2015. If you think that is inaccurate, you might wish to post there :)What you say is actually a bit strange: the header files etc. belong to a particular Qt version, hence it would make sense if they define the Qt version for which they work. Defining your own value for
QT_VERSION
isn't going to help much when they were written for a different version....