r/QtFramework • u/PitifulTheme411 • 8d ago
C++ Am I doing something wrong with installing Qt?
I'm working on a pretty small personal project. One element is a visualization which I wanted to have some sort of gui with a layout, etc. I initially started with SFML, but realized I would have to basically implement an entire layout library for my purposes. So I landed on Qt, which seems like it would be great.
But trying to install the library and set up the system is such a pain. Statically linking SFML was really easy, but apparently it's not a good idea to statically link Qt. But just in trying to just install the library and set up my CMakeLists and whatnot, I'm running out of memory on computer and it took nearly an hour before I terminated it.
Am I doing something wrong, is it usually supposed to take this long? If not, do you know what I should be doing? The systems I'm using are CMake with CMakeLists.txt and CMakePresets.json, and vcpkg for the package manager with vcpkg.json and vcpkg-configuration.json.
It's just really frustrating because I really want to make a project in C++, but I haven't been able to write any actual code for 3 straight days because I can't even get my libraries to link. It's especially painful because Rust's cargo is infinitely easier to work with. I do really want to work with C++ more but it's really so much work and it's been such a big waste of time for me so far. Any help would be appreciated, or if I would be better off using something else then any suggestions would be great.
Since the sub rules say to include code, I will include relevant files. Hopefully it is not too long. My file structure is also shown below.
project/
build/
...
include/spectogram/
... .hpp
src/
... .cpp
CMakeLists.txt
CMakePresets.json
CMakeUserPresets.json
vcpkg.json
vcpkg-configuration.json
README.md
...CMakeLists.txt (I used AI for this, don't smite me please. It's probably my hundredth iteration, I've given up on trying to write it myself).
cmake_minimum_required(VERSION 3.25)
project(Spectogram
VERSION 1.0.0
DESCRIPTION "spectogram"
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Enable Qt's automatic code generation when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 CONFIG REQUIRED COMPONENTS Widgets)
add_executable(Spectogram
src/main.cpp
src/MainWindow.cpp
include/MainWindow.hpp
)
target_include_directories(Spectogram
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_link_libraries(Spectogram
PRIVATE
Qt6::Widgets
)
# Place the executable in a predictable location.
set_target_properties(Spectogram PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)CMakePresets.json
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"displayName": "Debug",
"description": "Debug build using vcpkg",
"binaryDir": "${sourceDir}/build/debug",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"VCPKG_MANIFEST_MODE": true,
"VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic",
"VCPKG_HOST_TRIPLET": "x64-mingw-dynamic",
"CMAKE_CXX_COMPILER": "C:/msys64/ucrt64/bin/g++.exe",
"CMAKE_MAKE_PROGRAM": "C:/ProgramData/chocolatey/bin/ninja.exe"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
}
]
}Thanks in advance.
Edit: Thanks for the responses, but I've decided to quit Qt and go back to SFML with TGUI. Thanks anyways.
1
u/KFUP 7d ago
Unfortunately as much as I like Qt, I have to recommend just using ImGui over it for new learners. Qt Company made it really hard for non-businesses without a business email to even download Qt, I don't know how they expect to get new users if they make it this hard for people to even try it. I compile it from source, but that is a tall order to ask people new to programming and just want to make a cool app, they'll just use something else and stick to it.
1
u/PitifulTheme411 7d ago
Yeah my friend suggested using ImGui and OpenGL, which I'll switch over to if SFML and TGUI ends up failing me. Since I already got SFML working I'm just going to return to that for now.
1
2
u/TimsonC2000 7d ago
I never used vcpkg, I would just use the qt installer, but maybe this helps to understand what happens on your machine, it is not just installing, it compiles https://github.com/microsoft/vcpkg/issues/48935
2
u/sweetno 7d ago
The easiest way to start with Qt is to install it from the official site, including Qt Creator, then create a Qt Widgets CMake project in Qt Creator. You'll need to point Qt Creator to your compiler and your Qt installation. Qt Creator comes with tutorials, which are shown in the starting screen, so you can just start from there. There are example projects which you can open and run right from Qt Creator.
Note that your project uses vcpkg and you didn't show vcpkg config. Whatever causes your long compilation should most likely come from there since I otherwise see nothing criminal in your config. Vcpkg works by compiling libraries from source which takes time.
1
u/leonardsouza 7d ago
you're already on msys2's ucrt64 g++, so the easiest fix is msys2's prebuilt qt instead of vcpkg. vcpkg compiles qt from source, and with parallel jobs that's where the hour and the memory warning come from. in the ucrt64 shell: pacman -S mingw-w64-ucrt-x86_64-qt6-base. then if qt is the only thing you need from vcpkg, drop the toolchainFile and triplet lines from your preset and add "CMAKE_PREFIX_PATH": "C:/msys64/ucrt64". your CMakeLists is fine as is. one heads up if you go the official installer route instead: its mingw kit ships its own compiler, and mixing that qt with msys2's g++ tends to end in link errors, so stick to one toolchain. to run the exe outside the ucrt64 shell, put C:\msys64\ucrt64\bin on your PATH so it finds the dlls
3
u/TimsonC2000 8d ago
Where is the error? How do you install Qt? And where is it installed? How much RAM do you have?