From 5bc6d86424f2ddfd25667e10c1ad8a9324686088 Mon Sep 17 00:00:00 2001 From: daleclack Date: Tue, 23 Apr 2024 08:51:57 +0800 Subject: [PATCH] Add qt5 test3 --- Qt5/test3_list/.gitignore | 74 +++++++++++++++++++++++++++++++++++ Qt5/test3_list/CMakeLists.txt | 70 +++++++++++++++++++++++++++++++++ Qt5/test3_list/main.cpp | 11 ++++++ Qt5/test3_list/mainwindow.cpp | 14 +++++++ Qt5/test3_list/mainwindow.h | 23 +++++++++++ Qt5/test3_list/mainwindow.ui | 47 ++++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 Qt5/test3_list/.gitignore create mode 100644 Qt5/test3_list/CMakeLists.txt create mode 100644 Qt5/test3_list/main.cpp create mode 100644 Qt5/test3_list/mainwindow.cpp create mode 100644 Qt5/test3_list/mainwindow.h create mode 100644 Qt5/test3_list/mainwindow.ui diff --git a/Qt5/test3_list/.gitignore b/Qt5/test3_list/.gitignore new file mode 100644 index 0000000..4a0b530 --- /dev/null +++ b/Qt5/test3_list/.gitignore @@ -0,0 +1,74 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/Qt5/test3_list/CMakeLists.txt b/Qt5/test3_list/CMakeLists.txt new file mode 100644 index 0000000..9fdd530 --- /dev/null +++ b/Qt5/test3_list/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.5) + +project(test3_list VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(test3_list + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET test3_list APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(test3_list SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(test3_list + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(test3_list PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. +# If you are developing for iOS or macOS you should consider setting an +# explicit, fixed bundle identifier manually though. +if(${QT_VERSION} VERSION_LESS 6.1.0) + set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.test3_list) +endif() +set_target_properties(test3_list PROPERTIES + ${BUNDLE_ID_OPTION} + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +include(GNUInstallDirs) +install(TARGETS test3_list + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(test3_list) +endif() diff --git a/Qt5/test3_list/main.cpp b/Qt5/test3_list/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/Qt5/test3_list/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/Qt5/test3_list/mainwindow.cpp b/Qt5/test3_list/mainwindow.cpp new file mode 100644 index 0000000..6395a77 --- /dev/null +++ b/Qt5/test3_list/mainwindow.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/Qt5/test3_list/mainwindow.h b/Qt5/test3_list/mainwindow.h new file mode 100644 index 0000000..f7a3da3 --- /dev/null +++ b/Qt5/test3_list/mainwindow.h @@ -0,0 +1,23 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/Qt5/test3_list/mainwindow.ui b/Qt5/test3_list/mainwindow.ui new file mode 100644 index 0000000..421ed16 --- /dev/null +++ b/Qt5/test3_list/mainwindow.ui @@ -0,0 +1,47 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 9 + -1 + 791 + 431 + + + + + + + + + + + + + 0 + 0 + 800 + 30 + + + + + + + +