适配:解决运行时库缺失崩溃;解决WebEngineView无法在调试模式debug,解决方法是使用带调试符号的release;将html复制到执行目录,不再以资源文件加载

This commit is contained in:
zyuan 2025-06-25 11:14:44 +08:00
parent eca8d115bb
commit 07f7ac787b
3 changed files with 50 additions and 4 deletions

9
.gitignore vendored
View File

@ -10,6 +10,7 @@
*.sdf
# --- 编译产物 ---
bin/
*.o
*.a
*.so
@ -47,4 +48,10 @@ Thumbs.db
*.pdb
*.exp
*.manifest
*.lib
*.lib
#reportlog.log
reportlog.log
#QTlog
QTlog/

View File

@ -12,11 +12,14 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (Debug/Release/RelWithDebInfo/MinSizeRel)" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") # Debug
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") # Release[2,6](@ref)
if(MSVC)
#add_compile_options(/W4 /WX) # Windows:
add_compile_options(/utf-8)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Od /Zi /Fd${CMAKE_CURRENT_SOURCE_DIR}/bin/Release/DPS.pdb")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror) # Linux/macOS: [1](@ref)
endif()
@ -41,6 +44,9 @@ include_directories(include)
file(GLOB_RECURSE SOURCES "DataPlatform/*.cpp" "DataPlatform/*.c" "DataPlatform/*.cc") #
file(GLOB_RECURSE HEADERS "DataPlatform/*.hpp" "DataPlatform/*.h")
#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Qt
@ -70,6 +76,38 @@ elseif(UNIX AND NOT APPLE) # 明确排除 macOS
message(STATUS "Configuring for Linux")
endif()
#
if(WIN32)
set(MY_DLLS
WebQt.dll
CCSReport.dll
ODI_Common.dll
ODI_DPS.dll
CodeGenerator.dll
xlnt.dll
SqlcipherTool.dll
DBPService.dll
libeay32.dll
SqliteDBI.dll
)
foreach(dll ${MY_DLLS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/3th/release/${dll}"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/${dll}"
)
endforeach()
endif()
#
if(WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/DataPlatform/html"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/html"
)
endif()
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib

View File

@ -100,7 +100,8 @@ MainWindow::MainWindow(QWidget* parent)
_webView = new WebEngineView(QUrl(BaseUrl + "#/debug/SearchEditModule/save-data-to-file"), this);
#else
_webView = new WebEngineView(QUrl(BaseUrl), this);
QString indexHtmlPath = QCoreApplication::applicationDirPath() + "/" + "html/index.html";
_webView = new WebEngineView(QUrl::fromLocalFile(indexHtmlPath), this);
#endif // WEBDEGUB
this->setCentralWidget(_webView);
_eventModule = new SignalEventModule("MainWindow");