Is it possible to use Qt Creator without qmake? - c++

I've heard that it is possible to build non-Qt applications (like simple C++ HelloWorld) with Qt Creator. I downloaded and installed Qt Creator, and tried to compile simple code with it. But I didn't succeed: Creator needs qmake to create makefile.
Although the package I downloaded includes MinGW, there is no qmake inside of it.
I still want to use it just like an IDE to create simple C++ sources and compile them with MinGW. Is it possible to use Qt Creator without installing whole platform?

Qt Creator support CMake projects, you just need to choose Open a file or project and select the root CMakeList.txt of your project.
If you want to define your own build workflow, you can remove the default build step and create your own custom build steps (Qt Creator Build Steps).

I think you can modify the build step to remove qmake and use your custom make file.

You totally can!
You can write a .pro file yourself and use it as a project file to use QtCreator without linking / using any of the Qt libraries.
In Project / Compilation Parameters, you can actually tune the compilation steps (removing the qmake step and adding your own).
I use it for a big project of mine and it's very efficient: QtCreator's C analyzer is diamond.
Here's a sample project file for me:
TEMPLATE = app
TARGET =
DEPENDPATH += . include
INCLUDEPATH += . include
# Input
HEADERS += include/x.h \
include/y.h \
include/z.h
SOURCES += src/x.cpp
Note that I actually use qmake to generate this file automatically, but you can also put your hands into it and modify it by hand.
Afterwards, it's only a matter of $ qtcreator yourfile.pro.

Related

Qt: .pro file missing?

I tried to create a C++ project with Qt I stumbled across different kinds of guides which all refer to a special '.pro' file inside the project where I have to adjust a setting so the SQL part takes effect.
My problem: whenever I create a new project - doesn't matter whether its with qbs, qmake, or cmake - the project structure/ folder is lacking the '.pro' file.
Currently I'm using Qt 5.15.2 (via QT Creator) with MinGW Kit and cmake/ qbs.
As I'd like to play around with SQL-based apps.
Maybe I'm just skipping/ overlook something?
TL;DR: Use cmake. Forget about qbs and qmake.
Whenever I create a new project - doesn't matter whether its with qbs, qmake, or cmake - the project structure/ folder is lacking the '.pro' file.
A qmake project will have the .pro file, since that's the project file for qmake. Maybe you're looking in a wrong place? A qbs project will have a .qbs file, since that's what qbs uses. A cmake project will have CMakeLists.txt, since that's what cmake uses. It all works for me.
I'm just confused by all these guides stating that I have to add QT += widgets sql in the .pro file.
Those guides only apply when you use qmake, since .pro are qmake project files.
I suggest that you use cmake, as qbs is abandoned now, and there's no benefit to using Qt-specific qmake over the widely supported and continuously developed cmake.
Qt documentation covers the basics of how to use cmake to build Qt projects.
Qt support is provided natively by cmake, and it thus provides a comprehensive reference page.

How to build a project under the src directory of Qt?

I found a .pro file 5.12.1\Src\qtbase\src\plugins\platforms\windows\windows.pro and opened it in Qt Creator. After configuring a MingW kit, I tried to build the project. But I got this error;
error: vulkan/vulkan.h: No such file or directory
#include <vulkan/vulkan.h>
Do I need to configure something before building the project? I do not want the vulkan support, just want to compile it successfully. I remember if I build the whole Qt src, I need to run a command like "configure xxxxx" in the src directory. Now I do not want to build whole Qt, just this project. There is a line in windows.pro that seems related to this problem.
qtConfig(vulkan): QT += vulkan_support-private
How should I do to remove the need for the vulkan stuff in order to build it successfully?
Yes, you will need to configure things. I suggest you read up on Building Qt 5 from source to understand what is involved.

Generic c++ project in Qt creator - No rule to make target

I am trying to import a generic project into Qt creator by following this tutorial.
The project has its Makefile which builds multiple separate executables.
Running make all in the root directory of the project builds everything correctly.
The project has been imported into Qt creator and the sources show no errors regarding includes. When I press build, i get the error No rule to make targetall'. Stop.` As if the Makefile is non existent.
Where is Qt creator looking for the Makefile?
In my case the problem was with the custom build directory in the Build Settings.
Qt creator was searching for the Makefile in the build directory.
When using Qt creatror for Qt projects, I've usually set the build directory to something custom but this isn't sensible here :)

Using SFML with Qt creator?

I've recently began learning the SFML API for learning purposes but it seems to me like it only supports Codeblocks IDE and Visual Studio. I dislike both IDEs for my own ideas and I like the IDE that comes with Qt instead.
Is it possible to basically use SFML within the Qt creator?
EDIT:
I know some of you may some day find this on google, after struggling for 8 days to set up sfml to work with qt creator I've found the sollution:
step 1: Download the VS version of SFML from the website (NOT codeblocks version)
step 2: copy the DLLs from C:\SFML-1.6\lib to your system32 directory
step 3: open qt creator, make a plain C++ project, open your .pro file and add these lines:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
And you're done!
Short answer: Yes.
The IDE doesn't really matter all that much. The compiler does. Depending on the compiler used by Qt Creator, you download the appropriate SFML package. Most likely the MinGW based version will work just fine with your default install of Qt Creator. (I believe that relies on MinGW?)
All that then remains to be done is place SFML in its own directory and making sure that you set up the correct paths in your Qt Creator project. There's not much to it really.
I know i'm a little bit late to the party but:
SFML library is 100% compatible with qtcreator especially qmake.
Download SFML from https://www.sfml-dev.org/download/sfml/2.5.1/ . Bottom right minGW (You most likely have mingw on qt)
Place it somewhere you will know where it is. I usually put it in "C:/SFML-2.5.1"
There's a simple copy pasta you can add to your qmake '.pro' file:
INCLUDEPATH += "C:/SFML-2.5.1/include"
LIBS += -L"C:/SFML-2.5.1/lib"
CONFIG(debug, debug|release){
LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-system-d -lsfml-window-d
} else {
LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window
}
The 'INCLUDEPATH' includes the headers into your project where as the 'LIBS' adds the library file path. The 'CONFIG()' tells qt if you're running DEBUG mode or RELEASE mode.
This copy pasta is fun because you can also configure a custom wizard and make qt dropdown show you a 'create new sfml c++' project by just editing its profile with this.
Last but not least are the needed .dll files from 'C:\SFML-2.5.1\bin' You can add only the ones you need or all of them if you're lazy. You can do this by copying them into the BUILD folder of your project. (to find the build folder by default its a folder in the same path as your project folder with the name of your project prefixed by 'build-' or 'release-')
Make simple c++ project
Choose QMake build system
in project.pro add 2 lines:
CONFIG += link_pkgconfig
PKGCONFIG += sfml-all

How to get qmake to generate "project dependencies" in a Visual Studio .sln project

I have a qmake build of a few libraries and an app which depends on them. Using the subdirs template I'm able to get qmake to output a .sln file which works almost to my liking in VC2008. Though I've specified the dependencies between the targets in every way I've seen described, I end up with no "project dependencies" in the .sln file, and I have to add these in manually.
So far I've tried
CONFIG += ordered
with correct ordering to no avail.
And similarly the more arcane syntax:
client.depends = core common
Which also doesn't work. No dependencies whatsoever show up when I load the sln.
Both CONFIG += ordered and target.depends = are not supported by the qmake's MSVC backend (solution generator). Back in 2010 with Qt 4.7 around, the docs didn't mention that, but in Qt 4.8 the developers have updated the docs accordingly (see the Target section remarks):
.depends This subproject depends on specified subproject. Available only on platforms that use makefiles.
The ordered option is not supported for Visual Studio.
But they had provided a workaround (which is discussed in that cryptic post), and it's still valid and even documented in the same target section. Too bad I had to rebuild qmake and use a debugger to verify that:
a) There is a Lib/DLL project of which TARGET (the .lib is used and not the .dll) is used on the link line of another project in your solution (you can modify the link line with LIBS).
b) There is an Exe project of which TARGET is used in a custom build-step of another project in your solution.
You don't use paths in the TARGET variable (use DESTDIR/DLLDESTDIR for that), e.g, TARGET=$(SOME_VARIABLE)/myLib, won't work.
If you have a special location for your libs, you specify the -Lmy/library/path and LIBS += mylib, instead of just using LIBS += my/library/path/mylib
The leaf projects are created before you generate the solution file. (You can use the recursive flag for qmake to do this, like "qmake -tp vc -r [yourproject.pro]"
Basically, qmake will generate dependency when your lib's target name (yourlib.lib) is equal to the one of the import libraries of the final app (that has LIBS += yourlib.lib).
(See qmake's source where the import libraries are added as dependencies, and a little further where they're compared with the project target names)
Here is the minimal setup that generates dependencies in the solution:
solution.pro
TEMPLATE = vcsubdirs
SUBDIRS = main app
app/app.pro
LIBS += main.lib
main/main.pro
TARGET = main
TEMPLATE = vclib
With those, if you run qmake -r -tp vc, you'll get the explicit dependency in the generated .sln:
GlobalSection(ProjectDependencies) = postSolution
{E634D0EB-B004-3246-AADA-E383A376158F}.0 = {1BD6E999-63E6-36F5-99EE-1A650332198C}
EndGlobalSection
From an old mailing list entry:
http://lists.trolltech.com/qt-interest/2006-07/thread00238-0.html
It appears that it tries to figure out which things are dependent for you. Are you able to build from the sln without entering the project dependencies manually?
I am not a wiz in makefiles but if I were you, I would try to recreate that dependency in with QtCreator by editing the .pro file, running qmake then looking at the auto-generated result in the MAKLEFILE. If you want to know how qmake works then look at the qt documentation.