diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ed38372 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index c466bbb..b38cbda 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ -# template-mit +# Hello World Qt -Template with MIT license, protected `main` branch, and available `dev` branch. \ No newline at end of file +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 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fe77278 --- /dev/null +++ b/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +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(); +} \ No newline at end of file