aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-04 16:00:37 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-04 16:00:37 +0200
commit7ee1669522bdb6c2c6dae6a0ad7f9a9a60f87ff5 (patch)
treee97658f411184a15a0d893f9bfda225a606f03a0 /README.md
downloadminimal-qt-7ee1669522bdb6c2c6dae6a0ad7f9a9a60f87ff5.tar.gz
minimal-qt-7ee1669522bdb6c2c6dae6a0ad7f9a9a60f87ff5.zip
Initial commit
Diffstat (limited to 'README.md')
-rw-r--r--README.md80
1 files changed, 80 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a56ea9e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,80 @@
1# A minimal QT application, without the nonsense
2
3This repository contains a minimal QT application that can be compiled
4without using CMake or QT Creator.
5
6## Requirements
7
8* A C++ compiler (tested with GCC 14.2.1 and Clang 19.1.7, both on Linux-x86_64)
9* QT libraries and headers
10* The QT development tools `moc` and `uic`
11
12On Fedora Linux they are contained in the `qt6-qtbase-devel`. I have
13not tested this on other operating systems.
14
15## tl;dr
16
17If you just want to try out this program you can run (if you have `make` installed)
18
19```
20$ make && ./run
21```
22
23## Explanation
24
25Following the most basic QT Creator template, there are 4 source code files:
26
27* `main.cpp`: the main source file
28* `mainwindow.h`: the header file for the main window of the application
29* `mainwindow.cpp`: the C++ source for the main window
30* `mainwindow.ui`: the UI file with an XML description of the main window
31
32The compilation is done in 3 steps:
33
341. Pre-process `mainwindow.h` with `moc` to obtain `moc_mainwindow.cpp`
352. Compile `mainwindow.ui` with `uic` to obtain `ui_mainwindow.h`
363. Compile the C++ files, including `moc_mainwindow.cpp`
37
38The `Makefile` implements these three steps.
39
40The first two steps are straightforward: first you need to locate the
41`moc` and `uic` command - they are usually in the QT installation
42folder. For example I have them in `/usr/lib64/qt/libexec`. Then run:
43
44```
45$ /usr/lib64/qt/libexec/moc mainwindow.h > moc_mainwindow.cpp
46$ /usr/lib64/qt/libexex/uic mainwindow.ui > ui_mainwindow.h
47```
48
49These steps can be skipped if one prefers to write the `moc_` and `ui_`
50files directly, removing the dependency on the two tools.
51
52For the last step, one needs to include the header files and link with
53the QT libraries.
54
55On my system the header files are in `/usr/include/qt6`. This means I
56need to add the option `-I /usr/include/qt6` to my `gcc` command. This
57simple project also requires headers contained in a subfolder of this,
58so I will add a second `-I` option (see the full command below).
59
60As for the system libraries, in my case they are installed in a system
61folder that is scanned by default by the linker, so I don't have to
62specify the path. We need the files `libQt6Widgets.so`, `libQt6Core.so`
63and `libQt6Gui.so`, which we can include with
64`-lQt6Widgets -lQt6Core -lQt6Gui`. If your linker does not find them,
65locate them and include their folder with `-L /path/to/the/folder`.
66
67So the command for step 3 becomes:
68
69```
70$ g++ main.cpp mainwindow.cpp moc_mainwindow.cpp \
71 -I /usr/include/qt6 -I /usr/include/qt6/QtWidgets \
72 -lQt6Widgets -lQt6Core -lQt6Gui
73 -o run
74```
75
76And finally you can enjoy your new app:
77
78```
79$ ./run
80```

Generated with cgit - Back to sebastiano.tronto.net