Qt plugin options for configuring - qt

I am trying to build qtvirtualkeyboard plugin following this instructions with arrow-key-navigation option enabled. But I don't understand how to enable it in the right way. I have tried to add
CONFIG += arrow-key-navigation
into qtvirtualkeyboard.pro without any success. When I add
DEFINES += QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION
into src/virtualkeyboard/virtualkeyboard.pro it works, but I think this is the wrong way.

The sources should be pristine and you shouldn't be touching them. Delete the decompressed sources, and reinstall them.
The configuration options are passed to qmake, on the command line. E.g., assuming an out-of-source build (the only sane way!):
qmake /path/to/qtvirtualkeyboard.pro CONFIG+=arrow-key-navigation
These options can be specified in Qt Creator's build settings: there's a place to add qmake command line options to.

Related

How can I pass a command line CONFIG parameter to qmake from QtCreator?

I have a script used for CI builds that adds a CONFIG variable to qmake when building via Linux. I need to do the same for Windows desktop devs from within QtCreator. This needs to be an optional (every now and then) thing, rather than the default. Hence why it is not in the .pro file permanently.
Is this possible? And if so, how do I do it?
Edit:
Example of my situation is:
base.pro
SUBDIRS = common base
DESKTOP {
SUBDIRS += app
}
CI {
SUBDIRS += app support_tools
}
Build Script:
#!/bin/bash
qmake -makefile -r -Wall CONFIG+=CI
make
So what I'd like to be able to do is to (occasionally) do the CI style build from within QtCreator. In other words, I just need to be able to pass the additional CONFIG entry to qmake.
Yes, the users could edit the pro file, but that's annoying and has the chance of getting mistakenly committed. It doesn't seem like much of an ask to be able to pass something to qmake from Creator, but I couldn't see where.
You do that in the build settings of the project. You just add CONFIG+=CI in the qmake build step (click the "Details" button to expand it). Once you're done with testing, just remove it again. Or you can create a dedicated CI build configuration that always adds CONFIG+=CI. Although in your case, you probably just want to temporarily add that, build, and then remove it again.

Qt $$[...] - configuration option that were set when Qt was built

I'm looking at this Qt5 .pro file. It has the following entry:
DESTDIR = $$[QT_INSTALL_PLUGINS]/ms_plugins
I know that this means the compiled module's output (a plugin) should go into the ms_plugins subfolder in the Qt5 plugins install location. I have verified that the plugin does indeed go into that location.
My questions are:
Where is QT_INSTALL_PLUGINS defined?
On a related note, is there a similar variable that holds the
location of the build directory. Typically, something like
build_Desktop_Qt_5_2_1_clang_64bit-Debug on my Mac.
Any documentation of all available variables?
EDIT: I've found some description of these variables here, although, I still don't see where they're defined.
EDIT2: Mostly for future visitors. The documentation mentions The special $$[...] operator can be used to access various configuration options that were set when Qt was built:. So in order to figure out what QT_INSTALL_PLUGINS is we can put the following in a .pro file:
message(Plugins: $$[QT_INSTALL_PLUGINS])
QT_INSTALL_PLUGINS is one of the built-in properties of qmake. The manual of qmake in Qt 4.8 talks about qmake's built-in properties but does not mention QT_INSTALL_PLUGINS specifically. The manual of qmake in Qt 5 shows a much longer list of built-in properties including QT_INSTALL_PLUGINS. If you take a look at the source of qmake you can see that the value of a built-in property is determined by calling QLibraryInfo::location() (source, doc).
The location of the build directory can be found in a variable called OUT_PWD: OUT_PWD specifies the full path leading to the directory where qmake places the generated Makefile.
You can find the documentation of all available variables here.
QT_INSTALL_PLUGINS is a persistent property of qmake. You can print its value on the command line using
qmake -query QT_INSTALL_PLUGINS
To change this location, use qmake -set <property> <value>. Type qmake -help for more information.

How to access qt directories in .pro file?

I want to build qt application that will gather all the necessary binaries for standalone execution on install.
I know that can be done in lines of:
QT_DIR=C:/Qt/4.8.4
dlls_to_move.files += $$DIR/bin/QtCore.dll
however that seems clumsy. Is there a way to retrieve Qt binary folder actually used, like project directory that can be retrieved with $$PWD?
From qmake Advanced Usage:
The special $$[...] operator can be used to access various configuration options that were set when Qt was built:
So I think you'd want to do this in your project file:
dlls_to_move.files += $$[QT_INSTALL_BINS]/QtCore.dll

How can the install path be set for a qt project

I'm looking for the equivalent to ./configure --prefix= for qmake. Basically, I want to override the default install/deployment directory. How is this specified with command line qmake? I also use QtCreator to build a lot of my gui projects, and I'd like to know how to do the same thing while building inside of QtCreator. Is there a variable that I can manipulate in the .pro files to do this, or do I change my project settings?
Thanks!
For me, it seems that qmake PREFIX=/usr/local doesn't work
(try with the source of qtcreator)
So the solution is to use qmake normally, but then, you do
make
INSTALL_ROOT=/usr/local make install
I've found the solution to this, and it is just as easy as specifying the --prefix option to configure.
For qmake on the command line, you simpy add a PREFIX= parameter:
qmake PREFIX=/usr/local
There are two ways to do this in QtCreator. First, you could change your .pro file to include an explicit PREFIX variable definition. However, this is not recommended, as the prefix is a preference specific to each user, and it is preferable to keep the distributed project files generic. A better way to do this, is in your own project settings. Simply go to the build configuration that you are using, expand the qmake settings, and add PREFIX= to the additional arguments.

How to add pre processing defs (macros) to qt creator?

In Eclipse there is an option to specify pre processing defines (#ifdef macros) to a project by using the Symbols option in Paths and Symbols. This helps in effective indexing of code which is cross platform. Is there any option to provide these in Qt creator?
It depends:-)
The following is assuming you are using qmake based projects:
First you can add DEFINES += SOME_DEFINE=value into your .pro file. That is picked up inside creator and when building on the command line and should also show up when creating a MSVC or XCode project from the .pro file.
Then you can add DEFINES += SOME_DEFINE=value to the qmake call that Qt Creator will issue when configuring the project. That happens in the Project Mode, Build Settings, QMake Steps.
Finally, you can put #define SOME_DEFINE value liens into a header file and include that. That works for all kinds of projects:-)
From the QT Documentation:
The defines are specified in the .config file. The .config file is a
regular C++ file, prepended to all your source files when they are
parsed. Only use the .config file to add lines as in the example
below:
#define NAME value
That is, if you import a project named MyProject, then the pre-processor definitions should be specified in MyProject.config
For my projects it causes the indexer to recognize this define project wide and changed the auto-complete to reflect this.
I think the initial answers are good, but they require that you manage your configuration manually whereas there're ways to let the IDE manage this for you automatically based on whether you have a release or debug configuration selected.
This bit may be redundant, but please note that this will work for you only if you are using the IDE for building. Obviously, if this is not the case, you will need a different solution.
Steps
Since pictures are worth a thousand words, here's an example of how you define a debug macro for your debug build using Qt Creator 4.3.1:
Make sure you have your Debug configuration selected;
Go to the Projects section on the left menu;
Go to the Build section
Under Build Steps, look for the Additional arguments input box;
Enter your macro definitions (e.g. DEBUG for your #ifdef DEBUGs in the code; in my case it's __CTS_DEBUG__)
The macro will now only be defined when you're using your debug config; when you choose your Release config (see step 1), it will become undefined automatically and your conditionally-compiled debug code will be removed, as shown in the pictures below, which is just what you always wanted.
Results
With the debug config selected
With the release config selected:
I wanted to specify a #define string in the .pro file, but my code ended up with the contents of the string without the quotes. I had to escape the quotes, and then escape the escapes to get one pair of quotes to last all the way to my code. This is because qmake strips off one set of escapes and some quotes, then the command line strips off the rest of them. This worked for me:
DEFINES += "VERSION=\"\\\"0.1.0\\\"\""
On Windows, this VERSION string can then be used in the .rc file to create the version stuff where Windows wants it and as well as in code for an "About" menu.
You can define some PREPROCESSOR in the Project settings in QtCreator. I do not have QtCreator here but i remember there is a tab for project configuration.
First suggestion from #Tobias Hunger's answer worked for me. I was doing this in my .pro file:
DEFINE += KEY=value
which did not work until I changed it to:
DEFINES += KEY=value
That said, if you want to do everything from the command line, an almost hybrid solution that does not use Qt Creator GUI, but does use .pro files, is described here:
https://www.linux.org/threads/c-tutorial-create-qt-applications-without-qtcreator.18409/
Using the method described in the above link, you can use qtcreator -project to produce a .pro file, then use notepad or vim or some other text editor to add the DEFINES += KEY=value line to the .pro file you just created. Then use qmake thusly: qmake <your_project>.pro, to do the Qt pre-processing, and finally just make to build an executable.
I've also heard lore of a qtcreator -D option to add preprocessor defines from the command line as described here:
https://doc.qt.io/archives/qt-4.8/qmake-variable-reference.html#defines
but I've never tried it.
Hope something works for you! Your dedication to the CLI is admirable.

Resources