Qt-Creator doesn't create a .pro file - c++

I want to connect Qt with Sqlite. Everyone on YouTube says that we need to type QT += core gui sql inside of .pro file, but the problem is that after I created a Qt Widget Application I haven't found the .pro file. Probably the problem is connected with using CMake, but I cannot change to qmake, because our lecturer told us to use CMake in our coursework. I wish the problem is not that hard, and beautiful community is able to help me.

Since you created a CMake-based project, the corresponding project file is called CMakeLists.txt, not a .pro file.
The corresponding command to QT += sql for linking against the Qt Sql module, is find_package(Qt5 COMPONENTS Sql REQUIRED) for CMake projects.
See also the Get Started with CMake documentation from the Qt documentation.

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 implement GDAL library on Qt?

I need to make a GUI on Qt Creator using GDAL. I'm having some trouble while trying to implement GDAL on Qt Creator. I learned that I should've used MinGW for that. However, I could not find any documentation or instruction showing how to make implementation. Could you guys help?
I will try to help you and tell you what you have to do))
download library's binary, header file (if not found, have to build from lib source)
place in some local folder.
add in .pro file
INCLUDEPATH += .../GDAL/Maked/include
LIB += -L/path_to_lib -lgdal-20
run qmake,
build project,
move gdal-20.dll , libstdc++-6.dll , libiconv-2.dll
dlls in current working directory
how to work with her? you can see here
GDAL Warp API tutorial
Raster API tutorial
Using C++ Classes, Templates, and GDAL

How to build custom widgets for qt designer

I've read through the tutorials of Qt, I've searched the net, but I can't find the exact way on how to build custom witgets with Qt 5.8.x. In example with this tutorial one is able to build widgets for Qt 4.x as I already succeeded. For Qt 5.8.x I'am lacking in such straightforward tutorials.
Even if you use the build in wizard of Qt for setting up such custom widgets projects, one will end up with none recognized widget libraries.
So first of all, there is a confusion with the installing path, that the makefile should mention while installing the plugin.
In the project file one can find the section
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
After a straightforward installation of the open source mingw version of Qt 5.8.0 on a windows 7 machine in the path C:\Qt\Qt5.8.0, the variable "QT_INSTALL_PLUGINS" will extend to
C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins
thus the "target.path" for the
make install
will be read as
C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins\designer
But on the plain installation of Qt 5.8.0 with mingw the designer searches its plugins in
C:\Qt\Qt5.8.0\Tools\QtCreator\bin\plugins\designer\
As someone already suggested to me, one has to set the environment variable "QT_PLUGIN_PATH", where Qt Creator as well as Qt Designer ( in the subdirector "designer") searches its plugins in. So in order that Qt Creator still works properly one has to set the environment variable "QT_PLUGIN_PATH" to
the original path as well as to
the install path reffered to by $$[QT_INSTALL_PLUGINS]
So on my Windows 7 environment I set the variable "QT_PLUGIN_PATH" to
C:\Qt\Qt5.8.0\Tools\QtCreator\bin\plugins;C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins
Afterwards Qt Designer is able to find the custom build widget library. But Qt Designer it not able to load the library. One interesting thing is that the designer also refuses the libraries provided by the installation of Qt itself.
on loading the custom widget lib it says:
"... .dll can't be loaded: the given procedure was not found"
on loading the libs supplied by the Qt distribution itselfs in the path C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins\designer it says:
"... .dll cant be loaded: the mentioned modul was not found"
What I've done to build the library is, that I just ran through the project wizard to generate a custom widget for Qt Designer. With the so generated project I get the result of a non loadable lib, as mentioned above.
What do I have to change in the source/project files in order that the Qt Designer ist able to load the lib properly?
Thanks for any hints or suggestions!
You seem to use the MinGW compiler.
You cannot make plugins with that compiler with the default supplied Creator as it's compiled with Visual Studio 2013/2015 (depending on the Qt version).
Due to how DLLs works on Windows, you must use the same compiler that Creator is compiled with to build the plugin (otherwise it can't load it).
Go to "About Qt Creator" in the Help menu to check.
Also make sure to build the plugin in Release mode.

How can I use CLion (1.2.4) for a project involving Qt Creator?

Qt Creator makes GUI creation ridiculously easy, but I would rather use CLion for the coding part, and only use Qt Creator for the GUI editing.
Definitely possible!
I'm on a mac, so there are a few things that I do that won't work the exact same for other operating systems. They're small, simple things that a bit of google-fu should fix relatively painlessly.
Step 1: Create a Qt Creator Project
I'll be using a widgets application for this example. I'll get to other types of projects a little later.
One thing that I would highly recommend is to change the build directory (under the Projects tab on the sidebar) to a relative path instead of an absolute one, especially if this is going into GitHub or the likes. I changed it to ./QtBinDebug.
Oh, and remember to copy or otherwise save in a separate location the contents of main.cpp for later.
That's it for Qt. We should only need to use Qt Creator when editing our GUI from now on.
Step 2: Open the project up in CLion
CLion need to create a few files in order to be able to work with our project. Tell CLion to make a new project, but name the project the exact same as the one we made in Qt Creator, and point CLion at the same path. It should warn you about files already existing, just ignore it.
CLion will have very helpfully overwritten main.cpp. Put what you copied from QtCreator back in there.
Step 3: Call the right Makefile
Qt Creator will actually generate it's own makefile that will call qmake, and do a whole bunch of other magic. It's insane... I can replace my existing CMakeLists.txt with
cmake_minimum_required(VERSION 3.3)
project(WindowTest)
set(QT_BIN "${PROJECT_SOURCE_DIR}/QtBinDebug")
add_custom_target(qtMakeFile COMMAND make -C ${QT_BIN})
This will build the project perfectly fine! The only problem is that CLion
only supports CMake projects right now. The above CMakeLists gets around that by telling CMake to just call make on the right makefile, but the IDE itself doesn't know how to interpret our code......
Step 4: Find out where the Qt libraries are installed
I installed Qt via Homebrew and found the libraries I needed at /usr/local/Cellar/qt5/5.5.1_2/lib/cmake. If you told Homebrew to link the installation, /usr/local/opt/qt5/lib/cmake will also work, and has the added benefit of keeping your Qt version up to date without needing to change anything!
Step 5: Linking in the Qt Libraries for CLion
If you're like me, you'd rather use CLion when it autocompletes everything and doesn't throw red text everywhere.
We need to tell CLion where to look for the libraries it's missing. For a basic Widgets project, I needed Qt5Core and Qt5Widgets. To see what you'll need for sure, check the makefile Qt Creator generated. You should find what you need near the top in the LIBS macro.
For the linking, we're going to be using the find_package(...) and target_link_libraries(...) commands. While we could hard-code everything into these two commands, I thought breaking it up a little would be a good idea.
One other small detail is the header file that Qt Creator places in the build directory. For a skeleton widgets project, it's ui_mainwindow.h. We can tell CLion where to look with an include_directories(...) command.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(WindowTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#Base QT directory
set(QT_PATH "/usr/local/opt/qt5")
#Build output path of your QT Creator project
set(QT_BIN "${PROJECT_SOURCE_DIR}/QtBinDebug")
#Qt5 paths
#Qt5 library path
set(QT5_LIB_DIR ${QT_PATH}/lib/cmake)
#Qt5 individual libraries
set(QT5_CORE ${QT_LIB_DIR}/Qt5Core)
set(QT5_WIDGETS ${QT_LIB_DIR}/Qt5Widgets)
set(QT5_GUI ${QT_LIB_DIR}/Qt5Gui)
#Libraries to link to. The :: is for convenience
set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Gui)
#Libraries required. Probably the same as above minus the '::'. find_package() will be called on these
set(QT_LIBRARIES_REQUIRED Qt5Core Qt5Widgets Qt5Gui)
#find packages
foreach(QT_LIBRARIES_REQUIRED ${QT_LIBRARIES_REQUIRED})
find_package( ${QT_LIBRARIES_REQUIRED} REQUIRED )
endforeach()
add_custom_target(qtMakefile COMMAND make -C ${QT_BIN})
include_directories(${QT_BIN})
set(SOURCE_FILES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui)
add_executable(WindowTest ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
Step 6: Setting up CLion to actually run the thing properly
There should be a configuration that popped up in the run configurations menu. For me, with the above CMake file, it's qtMakefile. We need to do one last thing with that target, so click "Edit configurations..."
We need to select the executable that CLion should run after building. In the section for Executable, click "Select other..." and select the widget's executable. Mine was in QtBinDebug/WindowTest.app/Contents/MacOS/WindowTest.
And that's it! Congratulations!
Downsides
Debugging doesn't work. The debugger isn't linking on a simple hello world I put into my test program. To be honest, though, I really don't want to go down that rabbit hole.
Upsides
Autocomplete out the wazoo

Is it possible to use Qt Creator without qmake?

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.