Does Qt maintain any sort of versioning information about your program like .NET does? Like the build number? Or does it provide an easy way to access the SVN revision?
No.
But if you're using qmake then you can set compiler flags in the build system based on the results of arbitrary commands, which might be usable to do what you want.
For example, if you were using git, you could do something like this in your .pro file:
REVISION = $$system(git rev-parse HEAD)
DEFINES += APP_REVISION=$$REVISION
That would give you an APP_REVISION macro when compiling your program, which you could use like this:
// stringize macro
#define _STR(X) #X
#define STR(X) _STR(X)
QTextStream(cout) << "MyApp revision " STR(APP_REVISION) << endl;
Related
I am using QtCreator 3.1.1 to build a cross-platform project, and so I arranged to have different compilation kits for targeting my desktop PC and my BeagleBoneBlack (BBB).
Now I would like to define some macro in qmake project file (.pro) which are specific only for a given kit.
In other words I would like do in my .pro file something like:
if(kit == BBB)
DEFINES += MY_BBB_MACRO
elseif(kit == Desktop)
DEFINES += MY_DESKTOP_MACRO
else
DEFINES += OTHER_MACRO
Is is possible? How can I do that?
I obtained some help on Qt forum (take a look here) about this problem...
Anyway the solution consists in using qmake built-in test functions.
Basically I've added some CONFIG directive in QtCreator's project management: in the following screenshot you can see for example you can see that I've added CONFIG+=BBB in the project configuration for BBB kit; in the same way I've added CONFIG+=AM335x and CONFIG+=Desktop to AM335x and Desktop kits, respectively...
Then, in my .pro file I've added something like:
and now in my source code I can use something like #ifdef PLATFORM_BBB, #ifdef PLATFORM_AM335X and #ifdef PLATFORM_DESKTOP for differentiating the program behavior depending on compilation kit.
I found another solution.
First, add additional arguments in Projects using CONFIG+=Variable name for kit.
And in .pro file, write some code like below.
Desktop {
message("Desktop is selected")
}
RPI {
message("rpi is selected")
target.path = /home/pi
INSTALLS += target
}
If you look at the general message tab, you can see that the setting works well.
Anyone managed to compile library QtOpenCL using Qt5 (possibly under Window)?
edit: I managed to compile the code by porting it to QT5. I leave here in the question the dirty parts that I would like to replace in my method and describe what I did in the answer.
I was not able to provide the include path to my opencl installation so I
manually modified src/opencl/opencl.pro by adding the line
INCLUDEPATH += " *[absolute path to the openCL include folder]* "
QMAKE_LIBDIR_OPENCL = "*[absolute path to the opencl lib folder]*"
manually modified src/openclgl/openclgl.pro by adding the line
INCPATH += " *[absolute path to the openCL include folder]* "
QMAKE_LIBDIR_OPENCL = "*[absolute path to the opencl lib folder]*"
Anyone knows how to fix this in a cleaner way?
Here are the changes I had to introduce:
Modify the .pro files in order to add the OpenCL library. This is still an open problem for me. How to fix this in a cleaner way?
Link the projects (both opencl.pro and openclgl.pro) to the additional required Qt module QtConcurrent:
QT += concurrent
Fix the #include style by removing the packages, e.g. #include <qtconcurrentrun.h> instead of the old #include
<QtCore/qtconcurrentrun.h>
Fix qclvector.cpp by replacing qMalloc, qfree, qMemCopy with, respectively, std::malloc, std::free, std::memcpy
Moreover modify the initialization of ref in the constructor from ref = 1 to ref.store(1);
Removing all the macros QT_LICENSED_MODULE
This is enough to compile at least QtOpenCL and QtOpenCLGL using QT5
Version numbers are needed all over a project; in installers, code, toolchains etc. I despise duplication. I want my version numbers to be stored in one central authoritative location.
I am working with C/C++ and using Qt on various platforms. In Qt, qmake projects specify version numbers like:
VERSION = 1.2.3
In code I use something like in a header like Version.h:
#define VERSION_MAJ 1
#define VERSION_MIN 2
#define VERSION_REV 3
#define VERSION_STRING \"VERSION_MAJ\" "." \"VERSION_MIN\" "." \"VERSION_REV\"
My installer toolchain has support for C preprocessing so I can use the same version specified in Version.h. However, I don't know how to get qmake to use the same version number. I thought I could preprocess the pro file, but that won't work as # characters mean a comment in pro files and the C preprocessor will fall over.
Anyone know of a good way to keep my version number centralised?
I use something like this in my build system
#.pro file
#Application version
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 0
DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\
"VERSION_MINOR=$$VERSION_MINOR"\
"VERSION_BUILD=$$VERSION_BUILD"
#Target version
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_BUILD}
And after that you can use VERSION_MAJOR and others as normal macro in your application.
If you want to be able to store your version numbers in a c header file, you can do so and then import them into the Qt project variables in the project file. Something like the below should work:
Version.h:
#define MY_MAJOR_VERSION 3
#define MY_MINOR_VERSION 1
.pro
HEADERS += Version.h
VERSION_MAJOR = MY_MAJOR_VERSION
VERSION_MINOR = MY_MINOR_VERSION
The advantage of doing it this way round is that you can then use your authoritative header file if you need to compile other parts of the project away from Qt.
I would like to use Autotools and QT4 together. For this i would like to use AutoTroll.
As the Website says, it should be very easy to use it. Unfortunately i was not able to do so.
I have a working Hello World example:
This is how my configure.ac looks like:
AC_INIT([Hello], [0.1], [bug-report#hello.example.com], [hello], [http://hello.example.com/])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.10 no-define foreign])
AC_PROG_CXX
AC_PROG_CC
AT_WITH_QT
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
My Makefile.am:
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
bin_PROGRAMS = hello
hello_SOURCES = src/*.cpp
My simple main.cpp with a QT include:
#include <iostream>
#include <QApplication> \\Added this to test if Autotools works correctly
int main()
{
std::cout << "Hello Worlasdasdsadd!" << std::endl;
return 0;
}
Can someone please help mit with this? An short Step by step would be very nice.
Thank you in advance.
Edit:
I don't know how to integrate this m4 makro (Autotroll) in my configuration. This is why i cannot provide any "Errors" or something else. The of the website does not help me to understand what to do.
I won't recommend you to mix QT and autotools. For QT projects is most recommended to use cmake/qmake. When you get any problems it would be easier to find answers, etc.
Furthermore, Autotroll seems unmaintained since 2008 and not tested with QT >= 4.4+, and it has rained a lot (really a lot, QML and QT 5.0 as examples) since then:
AutoTroll has been tested successfully with Qt 4.0+, Qt 4.1+, Qt 4.2+ and Qt 4.3+
If you just want to learn autotools, gtk/gnome, gnu-tools or just any c++/c/whatever-language project would make it easier for you. Find projects using autotools and learn what they need and what they use.
Another recommendation is that you look for presentations and talks explaining the autotools basis and tools flows.
All I can say is that Autotools is a big world, be patient.
In our project, we added some source and header files if a MACRO is defined. We do this like that, in the .pro file:
contains(DEFINES, MY_DEF) {
message("Support MY_DEF")
INCLUDEPATH += \
my_include_dir
SOURCES += \
source1.cpp \
source2.cpp
HEADERS += \
my_include_dir/header1.h \
my_include_dir/header2.h
FORMS += \
myform.ui
}
This works fine during the build. The files are not compiled if MY_DEF is not defined. MY_DEF is defined like that:
DEFINES += MY_DEF
Curiously, Qt Creator always display the files in the project tree, whereas MY_DEF is defined or not. If not defined, they are not used for the build, but they still are displayed and editable, searches can scan them, etc... Is it a bug of Qt Creator?
This is not a big issue, just a little annoying, because we don't know clearly if a file is part of the project or not.
It's intentional even. There's a special "accumulating" parsing mode to collect all files that are mentioned in .pro files (essentially the same that's used to collect "translatable strings") for display in the project tree. Otherwise things like "Replace in all files in a project" would yield different results depending on the platform or the context it is run in. [And it's not half of qmake that's included, but close to all of it...]
This seems to be an issue with QtCreator and how it reads the .pro files - it doesn't seem to actually fully parse the files, opting instead to just pick out certain bits. I've got the same issue with files that are only included on one platform or another - in QtCreator, they always show up.
I expect that the reason is either that they don't want to re-implement half of qmake just to get the file lists, OR that there are situations where trying to parse it 'correctly' would get the wrong answer, and they've chosen to be predictably wrong instead of randomly wrong.
In addition to the conditional includes in QMake, I add #ifdef around such conditional source code. That way I also see it visually drop out of compilation when the conditions are not met. It's not as good as having the files drop out entirely from the project tree, but it's better than allowing them to still appear like they are part of the build when editing them if they are not applicable.
Just for the sake of completeness and answer correctness. Probably someone else needs this example of root .pro file with conditional source tree:
TEMPLATE = subdirs
SUBDIRS = device
CONFIG -= debug_and_release
_SANDBOX_DIR = $$dirname(PWD)
_PLAYER_PRO = $${_SANDBOX_DIR}/player/player.pro
SUBDIRS = device
device.subdir = $${_SANDBOX_DIR}/proxy/libproxy
contains(QMAKE_PLATFORM, android) {
unset(_PLAYER_PRO)
} else {
SUBDIRS += player
player.file = $${_PLAYER_PRO}
player.depends = device
}
SUBDIRS += app
app.subdir = $${_SANDBOX_DIR}/display/display
app.depends = device
contains(SUBDIRS, player) {
app.depends += player
}