QtCreator on linux: 32-bits vs. 64-bits - qt

My laptop is 64-bits, so when I start to use Qt, I chose 64-bit QtCreator.
Now I'm facing a problem, I wish that the executable files I generated are runnnable on 32-bit linux system.
Can I set QtCreator to generate 32-bit executable files? So that I can decide I want to generate 32-bit ones or 64-bit ones.
I don't want to install another 32-bit QtCreator ><.

You will need to install a 32-bit Qt, at least. You shouldn't need to install a 32-bit Qt Creator, though.
Once you install a 32-bit Qt, you should be able to add that version to Qt Creator and have it work without much trouble. You may need to force Creator to use the linux-g++-32 mkspec while compiling. If you build the 32-bit Qt yourself, you can do this by configuring with -platform linux-g++-32. If you install it from a package, hopefully the package builder has already done this.

I've figure out how to generate 32-bit codes.
from the "project" tab in QtCreator:
Build Settings
Build Steps
QMake -> show detail
put following arguments in "Additional arguments":
-spec linux-g++-32 -r

Related

How to use MinGW-64 with Qt Creator

I am aware that there are many post about this, but I honestly didn't understood any of it.
So, how do I install a kit for my Qt Creator (open source 5.7)?
I already downloaded and installed MSYS2.... don't know what to do with it.
I already downloaded and installed Qt64 - NG.... no clue what to do next.
I just want to be able to develop in Qt and chose betwen MinGW 32 and MinGW 64.
Thanks in advance!
EDIT: I also checked the wiki page. Most of the commands didn't worked. And I was told that it is outdated.
I know that your question is how do you install a kit for your Qt Creator, but first I think it's needed an introduction (Sorry for your eyes, English it's not my native language)
Introduction
The intention is to use the GCC compiler under Windows, what mean we need MinGW (Minimalist GNU for Windows).
MinGW only works for 32 bits, so we need the 64 bits forks, what means to use the MinGW-w64 or TDM-GCC flavors.
MinGW , GCC compiler for 32bits applications.
MinGW-w64 , GCC compiler for 32 and 64 bits applications.
TDM-GCC , GCC compiler for 32 and 64 bits applications.
With that we can create our applications/programs in Windows. In addition, we have other two different tools:
Qt Framework library, for create GUI's/Interfaces with multi-platform compatibility.
Qt Creator , an C/C++ editor, with additional editing tools for the Qt Framework.
About the binary compatibility chain
When we make an application, we've to follow the chain of libraries compiled with the same compiler version, the same way we've to follow the application binary interface (32 or 64 bits) for those libraries.
This means, if we want to compile an application for 32 and 64 bits with MinGW-w64 5.3, plus the Qt 5.7 Framework, we need:
MinGW-w64 5.3 (with flags 32 bits in the config) and the Qt 5.7 Framwork 32 bits build compiled under MinGW-w64 (MinGW-w64 version 5.3 or lower as long as they maintain binary code compatibility with our compiler).
MinGW-w64 5.3 (with flags 64 bits in the config) and the Qt 5.7 Framwork 64 bits build compiled under MinGW-w64 (MinGW-w64 version 5.3 or lower as long as they maintain binary code compatibility with our compiler).
Now come the weird thing. At Qt official webpage it's only available the 32bits builds for MinGW... I don't know why...
Here is when come the Qt64-NG project, a place where get the Qt Framework 64bits binary packages for MinGW-w64. Unfortunately the project is closed, so only are available until the Qt 5.5 Framework version.
I don't know other place where to get newer 64bits Qt binary packages for MinGW-w64 (Maybe the ones at MSYS2 project? I didn't tried yet). So, if one need it, at this moment must be compiled by oneself (This is for answer your opensource 5.7 comment).
Install and configuration
Now your question. How to install a kit for your Qt Creator. I'm going to answer for 64bit binaries because it's what I use (and latter you just need to do the same thing for 32bits)
For use Qt Creator with MinGW-w64, one just need:
Download Qt Creator and install it. My advice is to download the 4.1 (or upper version) snapshots if one is going to use CMake projects.
Download MinGW-w64 (posix-seh , or your choice flavor) + decompress in one folder.
That's all, with this we can create 32 and 64 bits applications.
By other way, in addition to the above steps, if one want to create applications using the Qt Framework library (a GUI/Interface for our applications), it's needed the binary package, this case 64 bit (The 32bit binary package is available at the Qt official page)
Download Qt64-NG (posix-seh , or your above choose flavor) + decompress in one folder.After that it's needed to execute the qtbinpatcher.exe included in that directory, just a double click.Note: If you change this directory to other path, execute again qtbinpatcher.
Here is where end the installation process. In my case, I have all under the same folder. Example:
D:\Programacion\mingw64_5.3.0rev0\
D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\
Now you just need to configure QtCreator, in this case:
Tools > Options > C++ , Compilers, Add > MinGW
In name put the compiler version, MinGW-5.3 x64 It's the name that will be shown in Kits
In Compiler path browse for the C++ compiler path, in this case D:\Programacion\mingw64_5.3.0rev0\bin\g++.exeTake note in ABI it's selected to use 64 bits flags in the compiler. That's why we put in name x64. For 32 bits, just duplicate and change the selection.
Tools > Options > C++ , Debuggers, Add
In Path browse to the debugger path, in this case D:\Programacion\mingw64_5.3.0rev0\bin\gdb.exe
In name put the name showed at version, GDB 7.10.1 in this case.It's the name that will be shown in Kits
And, if one want to create 64bits programs using Qt Framework, in addition to the above:
Tools > Options > C++ , Qt versions, Add, and select the qmake.exe placed at the qt64-ng bin directory.
In this case is, D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\bin\qmake.exe
In name put Qt %{Qt:Version} (qt-5.5.0-x64-mingw510r0-seh)It's the name that will be shown in Kits tab
Now you just need to specify the Kit:
Tools > Options > C++ , Kits, Add
In name MinGW-5.3 x64 (Qt-5.5)
In compiler select MinGW-5.3 x64
In debugger select GDB 7.10.1
In Qt Version select Qt 5.5.0 (qt-5.5.0-x64-mingw510r0-seh)
And in CMake goes the CMake path if one is going to use it (I use it with Ninja ).
Note: For install Ninja just copy ninja.exe to the mingw-w64\bin directory, and at the Kit, in Cmake generator push change to generator->ninja , and Extra generator->CodeBlocks. Ninja launch several make commands at same time, what decreases compilation times.
Long text for 1 minute of configuration. The Kit is what we select for compile the project, and one can have as many Kits as one wish (CompilerA x32 + Qt5.x , CompilerB x64 + Qt5.x , CompilerX x64 + Qt4.8, etc, etc).
Now, before to finish, an important thing. After we create a project (and the project it's open), at the Projects selector (Ctrl+5) we've to take care of the Build Environment variables.
Those are the variables that are going to be added at the command who launch our Runs/Builds for testing and debug.
In PATH it's needed to put the paths to MinGW-w64 and to Qt64-NG. And under my humble opinion, I recommend to put it in that order because of dll's. Following our example:
PATH D:\Programacion\mingw64_5.3.0rev0\bin;D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\bin;the_other_paths
At QtCreator snapshots branch I don't need to check it, it's done automatically
Most of the C/C++ editors works that way. To install editor, specify compiler&debugger path, and specify Build Environment variables for launch from the editor (overriding those environment variable that we've in Windows).
Note: I recommend to compile Qt Creator with 64 bits, due as happen with the Framework, for Windows it's only available in 32 bit at the official Qt website
Alternative way
By other side, we have:
MSYS2 , a Linux like tools environment.
There is all the same, just we download/install the packages with the pacman command, and are available the 32 and 64 bit versions. Those applications need to be launched from MSYS2 shell. It's not a binary compatibility thing but a paths matter.
The libraries available at MSYS2 project can be used in the first tool chain I described (due are build under MinGW-w64 also).
EDIT: Corrected namings, the last explanation, and added Ninja's url and installation note.
You should decide if you are going to use the MSYS2 ecosystem or not. If you want to use MSYS2, you should uninstall the Qt software that you downloaded separately to avoid confusion. For the rest of this answer, I'll assume you are using MSYS2.
You can install these MSYS2 packages using pacman:
mingw-w64-i686-qt
mingw-w64-i686-qt-creator
mingw-w64-x86_64-qt
mingw-w64-x86_64-qt-creator
Then open up a MinGW-w64 32-bit or 64-bit shell using the appropriate shortcut in your Start Menu, and run "qtcreator" at the command line.
You can also use other build systems to build your software. I have used CMake successfully for building Qt applications in MSYS2, instead of Qt Creator.
Directly launching from explorer will also work, unless you need to use qtcreator's Autotools plugin in which case launching it from an msys2 shell is necessary (so that various environment variables are set correctly).

How to install QtDesigner?

I just installed Qt 5.4.1 on Windows 7. And there is no QtDesigner. Also there is no QtDesigner in MaintenanceTool.
How can I install it?
You can install and find QT Designer as follows (Windows environment):
Install latest QT (I'm using 5.8) from QT main site
Make sure you include "Qt 5.8 MinGW" component
QT Designer will be installed in C:\Qt\5.8\mingw53_32\bin\designer.exe
Note that the executable is named "designer.exe"
UPDATE - there is an easier way to install QT Designer without downloading GB's of data from QT:
Install the latest version of "pyqt5-tools" using pip install pyqt5-tools --pre
The "designer.exe" will be installed in ...Lib\site-packages\pyqt5_tools
If you are on macOS and use brew you may have installed qt already using brews installer.
In that case you already have QT Designer installed even though it is not mentioned anywhere.
You can find it here: /usr/local/Cellar/qt/<qtversion>/libexec/Designer.app
So to place it in your local apps folder you can create a symlink to it like this:
ln -sf /usr/local/Cellar/qt/5.11.1/libexec/Designer.app ~/Applications/.
Install QtDesigner on windows:
https://build-system.fman.io/qt-designer-download
install designer on Linux:
It can be installed using the apt package manager
sudo apt-get install python-qt4 qt4-designer
run the command designer and it will work for you
if it doesn't try /usr/bin/designer
it worked for me
i am using python 3.6 with pyqt-5.16
It is there. Create a form, click on the .ui file and it opens automatically.
Install the latest version of "pyqt5-tools" using pip install pyqt5-tools --pre
Then run the command (designer.exe) then you are good
pip install pyqt5-tools
refer: https://pypi.org/project/PyQt5Designer/
run the following commands in the given sequence
pip install PyQt5Designer
designer.exe
then press Enter. This opens Qt Designer window.
Expanding StonyBoy answer.
If you are on macOS, you have installed Qt5 with brew, and you want to access the Qt5 Designer app via command line (like on Linux), you can set a symlink to the actual executable as well, like this:
ln -sf /usr/local/Cellar/qt/5.13.1/libexec/Designer.app/Contents/MacOS/Designer /usr/local/opt/qt/bin/designer
This way, the designer command will be placed in the bin folder, together with the other Qt5 executables (as qmake). Thus, you will be able to launch it simply by typing designer in your shell.
Note: of course you must have the path of the Qt5 bin/ folder added to your PATH environmental variable, for being able to directly call designer in the shell. But brew added it for you when you installed Qt5.
I got pyqt5 installed along with the tools when I pip install pyqt5-tools. If you prefer PySide2, qt-tools will work better. You can emulate a "dry-run" by creating a fresh, disposable virtual environment to test on. Obvious, I know, but I use them infrequently enough that it takes me a while to remember sometimes :)
As of January 2023, the official Qt website does not provide Qt Designer as a standalone Application. Qt Designer can be obtained from:
Official source
Qt Creator + Qt base package
Offline installer for Qt Creator (Qt account required, has integrated Designer)
Qt base package
Online installer (Qt account required)
Custom Installation, select component
Qt-->{Qt Version of choice}-->{Architecture (usually MSVC 64-bit / Mingw64)}
aqtinstall (NO account needed)
In all official installations, the standalone designer.exe is located in the Qt bin folder (for Windows usually C:\Qt\{Version}\{Architecture}\bin).
Third party standalone applications
(potentially outdated)
https://github.com/mherrmann/fbs
(small file size)
From PyPi via pip
pyqt6-tools, pyqt5-tools, pyqt-tools, PyQt5Designer
For Qt newcomers, using Designer in Creator may be the better choice as it is very straightforward. Advanced users looking to set up a custom build infrastructure may be interested in aqtinstall instead.
I found it here:
..\Lib\site-packages\qt5_applications\Qt\bin

Qt Creator - setting up a kit with a cross-compiler

I'm attempting to use Qt creator to cross-compile a project, but have an issue matching the Qt version and my specified compiler toolchain.
I have created a Kit setting up a Device, selecting my toolchain as the compiler (GCC ARM Linux in this case), but I only have a locally installed system Qt (5.0.2 on Mint x86).
Qt Creator understandably tells me the compiler cannot produce code for the Qt version; all the guides I have found suggest using a Qt compiled for the target platform. This doesn't make sense though - it attempts to run qmake compiled for a different architecture and fails
How do I install or configure/compile a Qt version to work with the cross compiler? Maybe I can modify my existing one to understand this setup?
Thanks
This makes absolutely sense. The advice to use a Qt, which is compiled for your target platform is correct. But this does not mean that you use a Qt that was compiled natively on that target platform. You need to use a Qt, which was compiled with a special cross compiler on your host platform for your target platform. This way qmake and other build tools remain executable on your host, but create configurations for your target.
So, if you have a compiler, which can create ARM code, use it to build your Qt. Then you can create a kit in QtCreator out of this compiler/Qt pair.
Greenflow is right. I would like to add some information. I have cross compiled Qt 5.4.1 on Windows having an ARM Linux as target platform. You just need to configure the build properly. Here's what I did:
./configure -platform win32-g++ -xplatform linux-arm-gnueabihf-g++ .....
So Qt tools (qmake,moc,etc...) were built as Windows binaries and all the libraries were built as Linux binaries. Check for the available platforms in qtbase/mkspecs.

How to run a Qt application on a system where Qt is not installed?

I have made an application using QtWebKit, Qt4. I have the binary generated in Fedora 16. Now, I want to run that application on another PC (running some other Fedora version), where Qt is not installed. How can I package my Qt application so that it can run on a platform where Qt is not installed? Is there any command line utility as well as QtCreator utility to do so. I have tried "deploy all" command, but it didn't have any affect.
Create an Installer with the Qt Installer Framework and just supply all needed shared libraries (Win/OSX) or compile statically. Under Linux there is always the problem between system-wide libraries or bundled libraries. The documentation https://qt-project.org/doc/qt-5.0/qtdoc/deployment.html should give you a good start
Obviously, you need to have access to the qt libraries, which are exactly the same version that you used to compile your application.
There are two options :
link qt libraries statically
create a RPM package (see this how)
Also check Deploying Qt Applications.
Since you're deploying using rpm, to systems where Qt 4 rpms are available, you don't need to do anything besides simply adding a dependency on the qt to your rpm's specfile. The user installing your package using yum localinstall will get the Qt dependencies automatically installed. That's the correct way of doing it - it will keep your package size small.
Of course you need a separate rpm build for every fedora/centos major version out there, but that's almost always a requirement.
If your package needs newer Qt version than the one provided by the platform packages, you can still make a specific version dependency (say qt >= 4.7.0) and have a readme that indicates that newer packages can be obtained from a 3rd party repository (epel etc.)
For deployment under Linux I've used Bitrock Installer Tool.
The main thing before deploying is to check your dependencies. You can do that by using command:
ldd appName | grep libQt
After that you'll see list of dependencies. You'll have to set environment variable LD_LIBRARY_PATH to let linker know where're your libraries. To do that:
export LD_LIBRARY_PATH=.
. means current directory
And after that:
./appName $*
After that you'll be able to use your executable with Bitrock Installer Tool.

Qt building 64 bits

I have downloaded the source package of Qt, and am trying to build a 64 bit version, on a 64 bit, Windows 7 machine. I have read as much as I can on building Qt, but I must be missing something somewhere.
I open a 64 bit command shell, which some descriptions seem to think is the only thing necessary.
Next I call configure. However, should I be specifying a platform option? If so which one? There doesn't seem to be a win64 option, or anything similar.
Then I call nmake, which builds a bunch of stuff, but it still builds in 32 bits.
What am I missing? Any help would be amazing.
Here's the configure command I run to build Qt 4.7.1 on 64-bit Windows. The compiled libraries are, indeed, 64-bit. This is run from the 64-bit command line. I'm using the Windows Platform SDK, not Visual Studio, but as long as you are running vcvars64.bat (or something like that), your environment should be set.
configure -plugin-sql-sqlite -no-qt3support -no-webkit -developer-build -opensource -platform win32-msvc2008
nmake
That seems the correct way to do it. Have you build a 32 bits Qt on the same source tree before? You might try to restart with a fresh Qt source directory.

Resources