How to use QtPDF with MinGW + cmake ?
-
Hello,
I working on project which I want to create pdf file with workers data. I decided to use QtPdf which I used first time for MacOS version and everything was fine. However, now I want to prepare version for Windows with MinGW. But when I added QtPdf to my project I got several errors.
Below is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5) project(ORPHEUS 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 Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) find_package(Qt6 REQUIRED COMPONENTS Sql) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets PrintSupport Pdf) set(LIBRARY_PATH C:/Repositories/logger/build/Desktop_Qt_6_3_0_MinGW_64bit-Debug) include_directories(C:/Repositories/logger) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui Constants.h database.h database.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(ORPHEUS MANUAL_FINALIZATION ${PROJECT_SOURCES} workerdialog.h workerdialog.cpp workerdialog.ui Constants.h worktimemodel.h worktimemodel.cpp database.h database.cpp workerstablemodel.h workerstablemodel.cpp workplacesdialog.h workplacesdialog.cpp workplacesdialog.ui workerhistorymodel.h workerhistorymodel.cpp workerhistorydialog.h workerhistorydialog.cpp workerhistorydialog.ui logindialog.h logindialog.cpp logindialog.ui registerdialog.h registerdialog.cpp registerdialog.ui pdfcreator.h pdfcreator.cpp exportdatadialog.h exportdatadialog.cpp exportdatadialog.ui config.json ) # Define target properties for Android with Qt 6 as: # set_property(TARGET ORPHEUS 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(ORPHEUS 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(ORPHEUS ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(ORPHEUS PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt6::Sql Qt6::Core Qt6::Gui Qt6::Widgets Qt6::PrintSupport Qt6::Pdf "${LIBRARY_PATH}/LoggerLibrary.lib" ) add_custom_command(TARGET ORPHEUS POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LIBRARY_PATH}/LoggerLibrary.dll" $<TARGET_FILE_DIR:ORPHEUS> ) include(FetchContent) FetchContent_Declare( nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.11.2 ) FetchContent_MakeAvailable(nlohmann_json) target_link_libraries(ORPHEUS PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(ORPHEUS PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(ORPHEUS PRIVATE Qt6::Sql) #target_link_libraries(ORPHEUS PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::PrintSupport Qt6::Pdf) # 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.ORPHEUS) endif() set_target_properties(ORPHEUS 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 ORPHEUS BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(ORPHEUS) endif()
And I got the errors:
C:\Repositories\ORPHEUS\CMakeLists.txt:15: error: Unknown CMake command "_qt_internal_find_third_party_dependencies". Call stack: C:/Repositories/ORPHEUS/CMakeLists.txt:15 (find_package) C:/Qt/6.3.0/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:213 (find_package) C:/Qt/6.3.0/mingw_64/lib/cmake/Qt6Pdf/Qt6PdfConfig.cmake:43 (include) C:/Qt/6.3.0/mingw_64/lib/cmake/Qt6Pdf/Qt6PdfDependencies.cmake:34 (_qt_internal_find_third_party_dependencies) C:\Repositories\ORPHEUS\CMakeLists.txt:15: warning: Found package configuration file: C:/Qt/6.3.0/mingw_64/lib/cmake/Qt6Pdf/Qt6PdfConfig.cmake but it set Qt6Pdf_FOUND to FALSE so package "Qt6Pdf" is considered to be NOT FOUND. Call stack: C:/Repositories/ORPHEUS/CMakeLists.txt:15 (find_package) C:/Qt/6.3.0/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:213 (find_package)
Build&Run: Qt 6.3.0 MinGW_64
I would like to know how can I use QtPdf for my project with MinGW?
Have a good day -
Hi,
AFAIK, QtPdf is part of QtWebEngine which underlying dependency does not support MinGW.
-
@SGaist
I did not realise that "QtPdf is part of QtWebEngine" and hence will not compile with MinGW.
Since we field question about not being able to build webengine with MinGW pretty regularly, is there anywhere in the documentation which lists this, QtPDF and any other modules (e.g. Bluetooth, IIRC?) which will require MSVC under Windows, so that people know when starting out with MinGW? -
Thanks for your answer, gentlemen. Generally, I need two modules, QMySQL and QtPDF. I have recompiled QMySQL with MinGW, and QtPDF only with MSVC. If I understand correctly, the only way to make both QMySQL and QtPDF work for me will be to recompile the QMySQL plugin to MSVC. Probably.
-
@BushyAxis793 Correct. Everything must be same compilation/link chain.
-