├── .gitignore ├── CMake └── StringListUtils.cmake ├── CMakeLists.txt ├── Dependencies └── CMakeLists.txt ├── LICENSE ├── README.md └── Src ├── CMakeLists.txt ├── EntryPoint.cpp ├── Main ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── Resources ├── Files │ └── Icon │ │ ├── Icon.qrc │ │ ├── Qt.png │ │ ├── Qt_128x128.ico │ │ ├── Qt_256x256.ico │ │ ├── Qt_32x32.ico │ │ ├── Qt_48x48.ico │ │ ├── Qt_64x64.ico │ │ └── Qt_Raw.webp └── Translations │ ├── HelloWorld_en_US.ts │ └── HelloWorld_zh_CN.ts └── Test ├── CMakeLists.txt └── MainTest.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | /cmake-build-* 4 | /build 5 | 6 | *.user -------------------------------------------------------------------------------- /CMake/StringListUtils.cmake: -------------------------------------------------------------------------------- 1 | function(list_add_prefix OUTPUT_LIST PREFIX) 2 | foreach (item IN ITEMS ${ARGN}) 3 | list(APPEND RET "${PREFIX}${item}") 4 | endforeach() 5 | set(${OUTPUT_LIST} ${RET} PARENT_SCOPE) 6 | endfunction() -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | set(QT_PROJECT_NAME "PROJECT_NAME") 4 | set(EXECUTABLE_NAME "HelloWorld") 5 | 6 | set(CMAKE_C_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD 17) 8 | 9 | set(QT_COMPONENTS Core Gui Widgets) 10 | set(OTHER_LIBS) 11 | 12 | set(QT_PROJECT_LOCALES "zh_CN" "en_US") 13 | 14 | option(ENABLE_TEST "Enable Unit Test" OFF) 15 | 16 | project("${QT_PROJECT_NAME}") 17 | 18 | file(GLOB_RECURSE MODULES "CMake/*.cmake") 19 | foreach(item IN LISTS MODULES) 20 | include(${item}) 21 | endforeach() 22 | 23 | add_subdirectory(Dependencies) 24 | add_subdirectory(Src) 25 | -------------------------------------------------------------------------------- /Dependencies/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Dependencies/CMakeLists.txt -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Augtons 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Qt 5 CMake 工程模板 2 | 支持: 3 | 4 | - 自动生成本地化语言文件 (`*.qm`) 5 | - 资源文件 (`*.qrc`) 管理 6 | - 集成自动化测试 (`Google Test`),默认关闭,可手动启动 7 | 8 | **目录:** 9 | 10 | - [一、创建工程](#一创建工程) 11 | - [1、基本](#1基本) 12 | - [2、【可选】添加资源文件](#2可选添加资源文件) 13 | - [3、【可选】使用 Qt 语言家进行本地化](#3可选使用-qt-语言家进行本地化) 14 | - [二、自动化测试](#二自动化测试-google-test) 15 | - [1、启用单元测试](#1启用单元测试) 16 | - [2、编写单元测试](#2编写单元测试) 17 | - [3、运行单元测试](#3运行单元测试) 18 | 19 | # 一、创建工程 20 | ## 1、基本 21 | **1. 克隆本仓库** 22 | 23 | **2. 设置工程名,可执行文件名,依赖库** 24 | 25 | 在工程根目录的 `/CMakeLists.txt` 26 | 27 | ```cmake 28 | set(QT_PROJECT_NAME "<你的工程名>") 29 | set(EXECUTABLE_NAME "<你的主可执行文件名>") 30 | 31 | # Qt 子模块会被以 Qt:: 为前缀,用 target_link_libraries 添加到 target 32 | # 中括号部分可不填,如你的工程不需要三方库,则直接 set(OTHER_LIBS) 33 | set(QT_COMPONENTS [ ...]) 34 | set(OTHER_LIBS [<你的三方库> ...]) 35 | ``` 36 | 例如 37 | ```cmake 38 | # 工程名 39 | set(QT_PROJECT_NAME "ProjectName") 40 | 41 | # 可执行文件名 42 | set(EXECUTABLE_NAME "ProjectNameApp") 43 | 44 | # 依赖的 Qt 模块 45 | set(QT_COMPONENTS Core Gui Widgets) 46 | 47 | # 依赖的三方库 48 | set(OTHER_LIBS OpenSSL) 49 | ``` 50 | 51 | **3. 编写程序本体** 52 | 53 | 按照本项目规范,程序本体的源文件应该在 `/Src/Main` 及其子目录下。 54 | 构建系统会自动扫描其下的源文件,头文件目录,添加到构建系统。 55 | 这些源代码将允许入口点调用,也支持单元测试中调用。 56 | 57 | 你可以使用 `QtCreator` 的 UI 设计器,把 `*.ui` 文件放进去,构建系统会生成对应的 UI 代码。 58 | 59 | 整个应用程序的入口点在 `/Src/EntryPoint.cpp` 下。 60 | 61 | > 之所以这样设计,分离入口点,是为了更好地适配单元测试。 62 | 63 | ## 2、【可选】添加资源文件 64 | 按照本工程的规范,请放置资源文件到 `/Src/Resources/Files` 下,**支持自由创建子目录进行分组**。 65 | 66 | 之后请按照 Qt 规范,编写 `qrc` 文件,或者用 `QtCreator` 生成,放到此处或其任意子目录下。 67 | **构建系统会自动扫描所有 `qrc` 文件**并添加到构建系统。 68 | 69 | `qrc` 文件中所有 `file` 字段的路径,既支持以 `qrc` 文件的相对路径填写,也支持以对应文件绝对路径填写。 70 | 71 | Qt 的资源文件有两种方式,一种是集成到代码里,另一种是生成独立的二进制文件。 72 | 前者适用于较小的文件,**后者适用于较大的文件**。 73 | 74 | 在本工程里,你可以指定 `*.qrc` 和 `*.big.qrc` **两种格式**的 `qrc`,本项目的 CMake 会分别扫描,并分别按两种方式编译资源。 75 | 76 | **对于大文件,推荐使用 `*.big.qrc`!** 77 | 78 | > 你也可以修改 `/Src/CMakeLists.txt` 的 `set` 来更改规定的资源文件扫描目录 79 | 80 | ## 3、【可选】使用 Qt 语言家进行本地化 81 | 82 | 在工程根目录的 `/CMakeLists.txt` 中,声明工程所需本地化的语言 83 | 84 | > 你也可以对此功能视而不见,而直接把你想要的语言放到源码里和 UI 设计文件里,测试正常即可。 85 | 86 | ```cmake 87 | set(QT_PROJECT_LOCALES "zh_CN" "en_US") 88 | ``` 89 | 90 | 构建一次项目,即可在 `/Src/Resources/Translations` 下生成 `*.ts (xml)` 文件,即翻译文件 91 | 可用 Qt 语言家 (`Linguist`) 软件进行编辑。 92 | 93 | 你可使用本项目自动生成的名为 `UpdateTranslation` 的 CMake Target 进行更新翻译。 94 | 95 | # 二、自动化测试 (Google Test) 96 | ## 1、启用单元测试 97 | 在工程根目录的 `/CMakeLists.txt` 98 | ```cmake 99 | option(ENABLE_TEST "Enable Unit Test" OFF) 100 | ``` 101 | 然后设置 Google Test 的仓库和版本 102 | 在工程根目录的 `/Src/Test/CMakeLists.txt` 103 | 104 | ```cmake 105 | set(GOOGLE_TEST_REPO "https://github.com/google/googletest.git") 106 | set(GOOGLE_TEST_VERSION "v1.14.0") 107 | ``` 108 | 109 | ## 2、编写单元测试 110 | 按照本项目规范,程序本体的源文件应该在 `/Src/Test` 及其子目录下。构建系统会自动扫描。 111 | 112 | ## 3、运行单元测试 113 | 使用支持 CMake 单元测试的 IDE 运行单元测试 (如 CLion, QtCreator) 114 | 115 | 或直接构建 `<可执行文件名>_Test` 这个 Target, 116 | 然后直接运行测试对应的可执行文件,或通过 Google Test 的 filter 指定运行的测试。 117 | -------------------------------------------------------------------------------- /Src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project("${EXECUTABLE_NAME}") 2 | 3 | set(CMAKE_AUTOMOC ON) 4 | set(CMAKE_AUTORCC ON) 5 | set(CMAKE_AUTOUIC ON) 6 | 7 | set(MAIN_DIR "${PROJECT_SOURCE_DIR}/Main") 8 | set(TEST_DIR "${PROJECT_SOURCE_DIR}/Test") 9 | set(RESOURCES_DIR "${PROJECT_SOURCE_DIR}/Resources") 10 | set(QRC_DIR "${RESOURCES_DIR}/Files") 11 | set(TRANSLATIONS_DIR "${RESOURCES_DIR}/Translations") 12 | 13 | find_package(Qt5 COMPONENTS REQUIRED ${QT_COMPONENTS} LinguistTools) 14 | list_add_prefix(QT_LIBS "Qt::" ${QT_COMPONENTS}) 15 | 16 | # 扫描本地化翻译文件 17 | set(LOCALE_PREFIX "${PROJECT_NAME}") 18 | list(LENGTH QT_PROJECT_LOCALES localeNums) 19 | if(localeNums LESS_EQUAL 0) 20 | list(APPEND QT_PROJECT_LOCALES "en_US") 21 | endif() 22 | foreach(locale IN LISTS QT_PROJECT_LOCALES) 23 | list(APPEND LOCALIZATION_FILES "${TRANSLATIONS_DIR}/${LOCALE_PREFIX}_${locale}.ts") 24 | list(APPEND quoted_locale_names "\"${locale}\"") 25 | endforeach() 26 | # 把所有 Locale 名转成 C 数组 27 | list(JOIN quoted_locale_names ", " LOCALES_NAME_ARRAY) 28 | 29 | # 自定义 Target: 本地化 30 | qt5_create_translation(QM_FILES ${PROJECT_SOURCE_DIR} ${LOCALIZATION_FILES}) 31 | add_custom_target(UpdateTranslation ALL DEPENDS ${QM_FILES}) 32 | 33 | # 解析 *.qrc 资源文件 34 | file(GLOB_RECURSE QRC_FILES "${QRC_DIR}/*.qrc") 35 | foreach(item IN LISTS QRC_FILES) 36 | get_filename_component(ext_name ${item} EXT) 37 | if(ext_name MATCHES ".*\\.big\\.qrc$") 38 | list(APPEND BIG_QRC_FILES ${item}) 39 | else() 40 | list(APPEND SMALL_QRC_FILES ${item}) 41 | endif() 42 | endforeach() 43 | qt5_add_resources(RESOURCES_FILES ${SMALL_QRC_FILES}) 44 | qt5_add_big_resources(BIG_RESOURCES_FILE ${BIG_QRC_FILES}) 45 | 46 | # Target: 主程序 47 | list_add_prefix(SRC_EXPRESSIONS "${MAIN_DIR}/" "*.ui" "*.c" "*.cpp" "*.hpp" "*.cc") 48 | file(GLOB_RECURSE MAIN_SOURCES LIST_DIRECTORIES true ${SRC_EXPRESSIONS}) 49 | list(APPEND MAIN_SOURCES "${MAIN_DIR}") 50 | foreach (item IN LISTS MAIN_SOURCES) 51 | if (IS_DIRECTORY ${item}) 52 | list(APPEND MAIN_INCLUDE_DIR ${item}) 53 | continue() 54 | endif() 55 | list(APPEND MAIN_SRC ${item}) 56 | endforeach() 57 | 58 | add_library(MainLibrary STATIC ${MAIN_SRC} ${LOCALIZATION_FILES}) 59 | target_include_directories(MainLibrary PUBLIC ${MAIN_INCLUDE_DIR}) 60 | target_link_libraries(MainLibrary PUBLIC ${QT_LIBS} ${OTHER_LIBS}) 61 | target_compile_definitions(MainLibrary PUBLIC -DLOCALE_PREFIX="${LOCALE_PREFIX}") 62 | target_compile_definitions(MainLibrary PUBLIC -DLOCALES_NAME_ARRAY=${LOCALES_NAME_ARRAY}) 63 | 64 | # Target: 主程序入口 65 | if (WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL "Release") 66 | add_executable(${PROJECT_NAME} WIN32 EntryPoint.cpp ${RESOURCES_FILES} ${BIG_RESOURCES_FILE}) 67 | else() 68 | add_executable(${PROJECT_NAME} EntryPoint.cpp ${RESOURCES_FILES} ${BIG_RESOURCES_FILE}) 69 | endif() 70 | target_link_libraries(${PROJECT_NAME} PUBLIC MainLibrary) 71 | 72 | # TODO 自动化测试 73 | if(ENABLE_TEST) 74 | add_subdirectory(${TEST_DIR}) 75 | endif() 76 | -------------------------------------------------------------------------------- /Src/EntryPoint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "mainwindow.h" 7 | 8 | // 这个数组的内容来自 CMakeLists.txt 中对于支持的语言的设置 9 | const char *supportedLocales[] = { LOCALES_NAME_ARRAY }; 10 | 11 | // 入口 main 函数 12 | int main(int argc, char* argv[]) { 13 | QApplication app(argc, argv); 14 | 15 | // 获取默认 QLocale 对象 16 | QLocale defaultLocale = []() -> QString { 17 | QString systemLocale = QLocale::system().name(); 18 | for (const char* local : supportedLocales) { 19 | if (systemLocale == local) { 20 | return systemLocale; 21 | } 22 | } 23 | return supportedLocales[0]; 24 | }(); 25 | 26 | // 设置 Translator 对象 27 | QTranslator translator; 28 | translator.load(defaultLocale, LOCALE_PREFIX, "_", "./"); 29 | QApplication::installTranslator(&translator); 30 | 31 | // 运行主窗口 32 | MainWindow mv; 33 | mv.setWindowIcon(QIcon(":/Qt_48x48.ico")); 34 | mv.show(); 35 | 36 | return QApplication::exec(); 37 | } 38 | -------------------------------------------------------------------------------- /Src/Main/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | 6 | MainWindow::MainWindow(QWidget *parent) : 7 | QMainWindow(parent), 8 | ui(new Ui::MainWindow) 9 | { 10 | ui->setupUi(this); 11 | 12 | connect(ui->aboutBtn, &QPushButton::clicked, this, [this] { 13 | QMessageBox::aboutQt(this); 14 | }); 15 | 16 | connect(ui->helloBtn, &QPushButton::clicked, this, [this] { 17 | static uint32_t count = 0; 18 | ui->helloLabel->setText(tr("Hello World, %1").arg(++count)); 19 | }); 20 | } 21 | 22 | MainWindow::~MainWindow() 23 | { 24 | delete ui; 25 | } 26 | -------------------------------------------------------------------------------- /Src/Main/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /Src/Main/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 480 10 | 320 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 290 21 | 110 22 | 121 23 | 29 24 | 25 | 26 | 27 | About Qt 28 | 29 | 30 | 31 | 32 | 33 | 40 34 | 110 35 | 121 36 | 29 37 | 38 | 39 | 40 | Hello World 41 | 42 | 43 | 44 | 45 | 46 | 130 47 | 40 48 | 231 49 | 51 50 | 51 | 52 | 53 | 54 | 16 55 | 56 | 57 | 58 | Hello World, 0 59 | 60 | 61 | 62 | 63 | 64 | 65 | 0 66 | 0 67 | 480 68 | 26 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Icon.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Qt_32x32.ico 4 | Qt_48x48.ico 5 | Qt_64x64.ico 6 | Qt_128x128.ico 7 | Qt_256x256.ico 8 | 9 | -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt.png -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_128x128.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_128x128.ico -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_256x256.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_256x256.ico -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_32x32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_32x32.ico -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_48x48.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_48x48.ico -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_64x64.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_64x64.ico -------------------------------------------------------------------------------- /Src/Resources/Files/Icon/Qt_Raw.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Augtons/Qt5-Template/6314d5120cdf30cb00e91d9d26e8c990eb10b07e/Src/Resources/Files/Icon/Qt_Raw.webp -------------------------------------------------------------------------------- /Src/Resources/Translations/HelloWorld_en_US.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | MainWindow 9 | 10 | 11 | 12 | 13 | About Qt 14 | 15 | 16 | 17 | 18 | Hello World 19 | 20 | 21 | 22 | 23 | Hello World, 0 24 | 25 | 26 | 27 | 28 | Hello World, %1 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Src/Resources/Translations/HelloWorld_zh_CN.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MainWindow 6 | 7 | 8 | MainWindow 9 | 主窗口 10 | 11 | 12 | 13 | About Qt 14 | 关于 Qt 15 | 16 | 17 | 18 | Hello World 19 | 20 | 21 | 22 | 23 | Hello World, 0 24 | 25 | 26 | 27 | 28 | Hello World, %1 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Src/Test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(GOOGLE_TEST_REPO "https://github.com/google/googletest.git") 2 | set(GOOGLE_TEST_VERSION "v1.14.0") 3 | 4 | message("Enable Google Test") 5 | include(FetchContent) 6 | 7 | # 下载 Google Test 8 | FetchContent_Declare( 9 | googletest 10 | GIT_REPOSITORY ${GOOGLE_TEST_REPO} 11 | GIT_TAG ${GOOGLE_TEST_VERSION} 12 | ) 13 | set(gtest_force_shared_crt ON CACHE BOOL "gtest_force_shared_crt" FORCE) 14 | FetchContent_MakeAvailable(googletest) 15 | enable_testing() 16 | 17 | # Target: 测试程序入口 18 | set(TEST_SRC_EXPRESSIONS "*.ui" "*.c" "*.cpp" "*.hpp" "*.cc") 19 | file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES true ${TEST_SRC_EXPRESSIONS}) 20 | list(APPEND TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}) 21 | foreach (item IN LISTS TEST_SOURCES) 22 | if (IS_DIRECTORY ${item}) 23 | list(APPEND TEST_INCLUDE_DIR ${item}) 24 | continue() 25 | endif() 26 | list(APPEND TEST_SRC ${item}) 27 | endforeach() 28 | 29 | add_executable(${PROJECT_NAME}_Test ${TEST_SRC} ${LOCALIZATION_FILES} ${RESOURCES_FILES} ${BIG_RESOURCES_FILE}) 30 | target_include_directories(${PROJECT_NAME}_Test PUBLIC ${TEST_INCLUDE_DIR}) 31 | target_link_libraries(${PROJECT_NAME}_Test PUBLIC MainLibrary GTest::gtest_main) 32 | 33 | include(GoogleTest) 34 | gtest_discover_tests(${PROJECT_NAME}_Test) 35 | -------------------------------------------------------------------------------- /Src/Test/MainTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "gtest/gtest.h" 5 | 6 | int argc = 0; 7 | auto app = QApplication(argc, nullptr); 8 | 9 | TEST(MainTest, AboutQt) { 10 | QApplication::aboutQt(); 11 | } 12 | 13 | TEST(Main, MessageBox) { 14 | QMessageBox::information(nullptr, "Hello World", "Hello World"); 15 | } 16 | --------------------------------------------------------------------------------