diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 80 |
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 | |||
| 3 | This repository contains a minimal QT application that can be compiled | ||
| 4 | without 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 | |||
| 12 | On Fedora Linux they are contained in the `qt6-qtbase-devel`. I have | ||
| 13 | not tested this on other operating systems. | ||
| 14 | |||
| 15 | ## tl;dr | ||
| 16 | |||
| 17 | If 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 | |||
| 25 | Following 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 | |||
| 32 | The compilation is done in 3 steps: | ||
| 33 | |||
| 34 | 1. Pre-process `mainwindow.h` with `moc` to obtain `moc_mainwindow.cpp` | ||
| 35 | 2. Compile `mainwindow.ui` with `uic` to obtain `ui_mainwindow.h` | ||
| 36 | 3. Compile the C++ files, including `moc_mainwindow.cpp` | ||
| 37 | |||
| 38 | The `Makefile` implements these three steps. | ||
| 39 | |||
| 40 | The first two steps are straightforward: first you need to locate the | ||
| 41 | `moc` and `uic` command - they are usually in the QT installation | ||
| 42 | folder. 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 | |||
| 49 | These steps can be skipped if one prefers to write the `moc_` and `ui_` | ||
| 50 | files directly, removing the dependency on the two tools. | ||
| 51 | |||
| 52 | For the last step, one needs to include the header files and link with | ||
| 53 | the QT libraries. | ||
| 54 | |||
| 55 | On my system the header files are in `/usr/include/qt6`. This means I | ||
| 56 | need to add the option `-I /usr/include/qt6` to my `gcc` command. This | ||
| 57 | simple project also requires headers contained in a subfolder of this, | ||
| 58 | so I will add a second `-I` option (see the full command below). | ||
| 59 | |||
| 60 | As for the system libraries, in my case they are installed in a system | ||
| 61 | folder that is scanned by default by the linker, so I don't have to | ||
| 62 | specify the path. We need the files `libQt6Widgets.so`, `libQt6Core.so` | ||
| 63 | and `libQt6Gui.so`, which we can include with | ||
| 64 | `-lQt6Widgets -lQt6Core -lQt6Gui`. If your linker does not find them, | ||
| 65 | locate them and include their folder with `-L /path/to/the/folder`. | ||
| 66 | |||
| 67 | So 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 | |||
| 76 | And finally you can enjoy your new app: | ||
| 77 | |||
| 78 | ``` | ||
| 79 | $ ./run | ||
| 80 | ``` | ||
