Add example project.

This commit is contained in:
me committed 2026-10-17 16:56:59 -07:00
1 parent 0bea8e4901
commit bb38215c04
3 files changed
+78 -2

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.5)
project(hello-world-qt VERSION 1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 COMPONENTS Widgets REQUIRED)
add_executable(hello-world-qt main.cpp)
target_link_libraries(hello-world-qt PRIVATE Qt6::Widgets)
+23 -2
View File
@@ -1,3 +1,24 @@
# template-mit
# Hello World Qt
Template with MIT license, protected `main` branch, and available `dev` branch.
A simple Qt application that displays "Hello World!" in a window with a close button.
## Building
```bash
mkdir build
cd build
cmake ..
make
```
## Running
```bash
./hello-world-qt
```
## Dependencies
- Qt 6
- CMake
- C++17 compiler
+43
View File
@@ -0,0 +1,43 @@
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow mainWindow;
mainWindow.setWindowTitle("Hello World Qt");
mainWindow.resize(400, 300);
// Create central widget and layout
QWidget *centralWidget = new QWidget(&mainWindow);
QVBoxLayout *layout = new QVBoxLayout(centralWidget);
// Create hello world label
QLabel *helloLabel = new QLabel("Hello World!", centralWidget);
helloLabel->setAlignment(Qt::AlignCenter);
helloLabel->setStyleSheet("font-size: 24px; font-weight: bold;");
// Create close button
QPushButton *closeButton = new QPushButton("Close", centralWidget);
closeButton->setStyleSheet("font-size: 16px; padding: 10px;");
// Connect button to close action
QObject::connect(closeButton, &QPushButton::clicked, &mainWindow, &QMainWindow::close);
// Add widgets to layout
layout->addStretch();
layout->addWidget(helloLabel);
layout->addWidget(closeButton);
layout->addStretch();
// Set central widget
mainWindow.setCentralWidget(centralWidget);
// Show the window
mainWindow.show();
return app.exec();
}