Skip to content

Commit 43a5784

Browse files
pppanghu77deepin-bot[bot]
authored andcommitted
feat(tests): add Qt5/Qt6 compatibility support
- Add conditional package finding for Qt6 or Qt5 dependencies - Use generator expressions to link appropriate Qt version libraries - Add preprocessor conditionals for Qt6 vs Qt5 API usage - Maintain backward compatibility with both Qt frameworks
1 parent 6a118d7 commit 43a5784

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

tests/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
set(CMAKE_AUTOMOC ON)
2-
find_package(Qt6 REQUIRED COMPONENTS Core Test)
3-
find_package(Dtk6 REQUIRED COMPONENTS Core)
2+
if(Qt6_FOUND)
3+
find_package(Qt6 REQUIRED COMPONENTS Core Test)
4+
find_package(Dtk6 REQUIRED COMPONENTS Core)
5+
else()
6+
find_package(Qt5 REQUIRED COMPONENTS Core Test)
7+
find_package(DtkCore REQUIRED)
8+
endif()
49

510
# Enable testing
611
enable_testing()
@@ -25,16 +30,16 @@ add_executable(docparser_autotest ${AUTOTEST_SOURCES})
2530
target_link_libraries(docparser_test
2631
PRIVATE
2732
docparser
28-
Qt6::Core
29-
Dtk6::Core
33+
$<IF:$<BOOL:${Qt6_FOUND}>,Qt6::Core,Qt5::Core>
34+
$<IF:$<BOOL:${Qt6_FOUND}>,Dtk6::Core,Dtk::Core>
3035
)
3136

3237
# 链接自动化测试所需的库
3338
target_link_libraries(docparser_autotest
3439
PRIVATE
3540
docparser
36-
Qt6::Core
37-
Qt6::Test
41+
$<IF:$<BOOL:${Qt6_FOUND}>,Qt6::Core,Qt5::Core>
42+
$<IF:$<BOOL:${Qt6_FOUND}>,Qt6::Test,Qt5::Test>
3843
)
3944

4045
# 设置包含目录

tests/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -76,7 +76,11 @@ int main(int argc, char **argv)
7676
if (fromEncoding.toLower() != "utf-8") {
7777
auto in = QByteArray::fromStdString(content);
7878
QByteArray out;
79+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
7980
Dtk::Core::DTextEncoding::convertTextEncodingEx(in, out, "utf-8", fromEncoding);
81+
#else
82+
Dtk::Core::DTextEncoding::convertTextEncoding(in, out, "utf-8", fromEncoding);
83+
#endif
8084
content = out.toStdString();
8185
}
8286

0 commit comments

Comments
 (0)