How to run GNUMakefiles with QtCreator - qt-creator

I am trying to run one of the examples related to OpenDDS within Qt Creator.
the example available which is ishapes project doesn't have any .pro file.
how can I run the project? it only have the .h, cpp and the GNUMakefile.

Related

Make Qt's Debugger Aware of DLL Dependency in CMake (Windows)

In Windows, I have a CMake build under Qt that locates, via a find_library command, an A.lib file that is in a separate directory relative to its A.dll file. The A.lib file is then linked using a target_link_libraries command.
As far as the build goes, CMake has no problem not having the symbols in the .lib file defined until runtime.
At runtime, I use windeployqt to successfully assemble all dependent libraries (indluding the A.dll file) into a separate deploy directory from the build directory, and I'm able to run there just fine.
However, to run via Qt's debugger, Qt runs the executable from the build folder rather than the deploy folder. By default, Qt attempts to add the build library folders to the PATH variable as well. Admirably, it also attempts to scan dependencies such as the Qt libraries and the path to A.lib and adds them to the PATH as well. Unfortunately, it does not add the path to A.dll, resulting in a failed DLL dependency error in the launched thread.
I can easily get around this by adding the path to A.dll to the PATH in Qt's run section of the Project tab. However, I'm curious, is it possible to make Qt catch this dependency via some CMake command and automatically add A.dll to the PATH, similar to how it caught other dependencies correctly? I'm not sure how Qt attempts to find dependencies, but in a previous QMake iteration of the build, the path to A.dll was appended automatically.
As of Qt 7.0.1, Qt added a workaround that allows the user to add dll paths to CMake via a target_link_directories command and have those parsed by Qt from the Cmake file-api to add to the PATH variable in Windows.
This fix is in Qt Creator 7.0.1, see the change summary here:
https://codereview.qt-project.org/c/qt-creator/qt-creator/+/404290
And the issue prompting this change on the official Qt website (which is where I should've looked first):
https://bugreports.qt.io/browse/QTCREATORBUG-27201?workflowName=Qt+Bug+Tracking+v2.4&stepId=8
It should be noted that a workaround for this issue was added to Qt Creator at an earlier point (I'm not sure exactly when) that looked one directory above the \lib folder for a \bin folder (see the code that implements this workaround, and performs the CMake file-api queries in general here).
The latter workaround happened to not work for my particular MSVC-built library folders, since there the lib and bin folders are themselves in folders with architecture and OS information, with a common parent three and two folders above, respectively.
Updating Qt Creator to 7.0.1 and using the target_link_directories command solves this issue.

How to setup meson with Qt creator

I normally use Qt creator with cmake to program C++ projects. Lately I read quite a bit about meson and it's simplicity and I like to test it. This example explains how to setup meson.
When using meson, I like however to still use Qt creators shortcuts for building (ctrl + B) or running (ctrl + R). How can I configure Qt creator to build a meson project, when I'm using a "generic project"?
Meson is currently not directly supported by Qt Creator. There is a bug report requesting that: https://bugreports.qt.io/browse/QTCREATORBUG-18117 and I am considering to actually implement that.
For the time being I use meson via the "Generic Project". Go to "New File or Project", "Import Project" and there "Import Existing Project". That gets you a dialog where you can select the files that your project consists of.
After that is done you will need to edit "projectname.includes" and add the include directories (one per line) into that file. Then you need to edit "projectname.config" and add defines (one per line) there.
Finally you will need to edit the build configuration and call ninja instead of make there.
With that it works reasonably well for my small project.
Until the QtCreator supports directly meson.build project files, I find this python2 script useful to create QtCreator generic project files: https://github.com/mbitsnbites/meson2ide
with meson and ninja in your PATH, this should work:
$ meson builddir
$ python2 meson2ide.py builddir
this generates a .creator project file in builddir (if you get an error about "mesonintrospect" not found, try this PR: https://github.com/mbitsnbites/meson2ide/pull/1)
To make CTRL+B work properly, In QtCreator build settings, remove the make build step and add a custom build step with the path to the ninja executable, and add the command line arguments
3>&1 1>&2 2>&3
Those redirect allow QtCreator to capture build errors in the "issue" panel.

How to create a Code::Blocks project from the cmake file?

I would like to use the Code::Blocks IDE to build a C++ project based on a CMakeLists.txt file. Previously, I was using Qt Creator, where I could open a CMakeLists.txt file directly, which would create a project. I could then define the build commands, eg. cmake ../src followed by make -j8. This would run cmake on the CMakeLists.txt file, and then run make on the makefile.
How can I do something similar in Code::Blocks? If I try to create a new project, it gives me the option of creating an empty project, but then I am stuck as to where to go next...
It's similar but you have to specify the compiler, supposing that you have a folder project/build and project/src and your CMakeLists.txt is under /project. Then your commands should be something as the following :
$ cd build/
$ cmake .. -G"CodeBlocks - Unix Makefiles"
you will have your CodeBlocks project created on the /build.
Code::Blocks, has its own .cbp files which do the same things as Makefile automatically.
Therefore Code::blocks canot generate a Makefile, but you can build your project from an alredy existing Makefile, i've found a very good explaination of it on the code::blocks wiki. I do hope this will help you :)

Automatically include Qt libraries in the .app bundle deploying on Mac

I am using Qt Creator to deploy my Qt application. On Mac, I'd like to include the required Qt libraries in the .app bundle. Is there any way to do it automatically using Qt Creator? Should I do it using the command-line? In that case, how should I do it?
The macdeployqt command line tool will add all the necessary Qt libraries that your Qt project references.
If you require any other, 3rd party libraries, you'll need to copy these manually and set the paths to them using the install_name_tool command.
You can check which libraries your application references using the otool command. For example: -
otool -L MyApplication.app/Contents/MacOS/MyApplication
For Qt Creator, I tend to write a script that adds the necessary libraries and calls macdeployqt and then under Projects, add a build step which calls the script.
An example script that would just add the Qt libraries would look something like this: -
#!/bin/bash
pwd
echo Copying QT libraries...
macdeployqt ./MyApplication.app
You can simply run macdeployqt foo.app. Qt Creator does not support this feature off-hand either. However, you can inject custom commands into your process in the QtCreator project settings.
It does not support QML just yet though. There are patches under codereview where it is coming. See the following link for details:
https://codereview.qt-project.org/#q,status:open+project:qt/qttools,n,z
Note: macdeployqt should not be used for usual development and debug! It should be only used when deploying. Otherwise, it is executed each time for building even if you just recompile the code due to a minor change for testing. This can slow down that process, but as for deploying, it should be alright.
On QT6 I was able to do it entirely within QT Creator:
In Projects/Build, add a custom build step after 'make' (probably only want to do this for your 'release' configuration):
Command: %{Qt:QT_HOST_PREFIX}/bin/macdeployqt
Arguments: %{ActiveProject:BuildConfig:Path}/%{ActiveProject:Name}.app - qmldir=%{ActiveProject:NativePath}
Working Directory: %{buildDir}
I was able to test it by airdropping the resulting .app onto my test machine.
reference: https://doc.qt.io/qt-6/macos-deployment.html#macdeploy

How to deploy my application using Qt-Creator?

I'm trying to deploy my simple Qt project like a hello world.
I build it successfully and can also execute it on Qt-Creator. However, I can't execute the binary directly in the release folder due to some shared library errors.
So I just copy some essential librarys to the release folder such as qtcore.dll and qtgui.dll, but I can't still execute it.
How can I deploy my simple Qt project? Is there an another step to deploy it?
You also need to deploy the MINGW runtime dll (mingwm10.dll). This file is located in your Qt\2009.5\mingw\bin directory.
Also pay attention to whether your application is compiled in debug mode or release mode. I just made the test with an hello world type application and Qt Creator. In the debug folders, I copied libgcc_s_dw2-1.dll, mingwm10.dll, QtCored4.dll and QtGuid4.dll and it works.
Pay attention to the d in dll names, which stands for debug: QtCore d 4.dll.
See Qt 4.6: Deploying an Application in Windows.
For Qt 5, check this page.
If you don't want to have dependencies with qt/mingw dlls you should compile qt statically as explain here: http://qt.nokia.com/doc/4.6/deployment-windows.html#static-linking.
You may also use static linking, just add this line into the .pro file:
QMAKE_LFLAGS += -static-libgcc
I found the solution here and successfully tested on WinXP with QT creator 2.2.0
Try running dependency walker on it (http://dependencywalker.com/) to see which dlls are missing?
Generally, you won't need to move those Qt libraries into your local folder since the Qt installation should've added those libraries into your path.
One possibility is that you built debug, and the Qt debug dlls are named differently
copy all the qt dlls to your windows directory directly "C:\Windows\" and there will be no qt dll error
100% working and simple
nb: do not create a qt dll folder in your windows directory post them as they are

Resources