From 206c37f6200cfbf4f79ca596b19b6ed565a786dc Mon Sep 17 00:00:00 2001 From: Shane Ringrose Date: Sun, 12 Jul 2026 22:32:42 +1200 Subject: [PATCH] cmake(qt6): verify Qt6::GuiPrivate at configure time, drop #warning (QPdfEngine::drawHyperlink) needs Qt's private GUI module, previously flagged only by a #warning at compile time. Qt >= 6.7 ships GuiPrivate as a proper find_package component, but some distro packages (e.g. Ubuntu's qt6-base-private-dev, Qt 6.8.3) do not install Qt6GuiPrivateConfig.cmake and only provide the implicit Qt6::GuiPrivate target created alongside Qt6::Gui. Requesting the component unconditionally would therefore break distro-Qt builds. Instead: try the component quietly, then hard-verify the Qt6::GuiPrivate target exists after the main find_package, failing at configure time with an actionable message if the private headers are missing. The compile-time #warning in pdf_links.cpp and projectprintwindow.cpp is now redundant and removed. Verified: cmake configure + compile of both translation units on Ubuntu 25.04 / Qt 6.8.3 (system KF6), cmake configure on Qt 5.15. Co-Authored-By: Claude Fable 5 --- CMakeLists.txt | 31 ++++++++++++++-------------- sources/pdf_links.cpp | 4 ++-- sources/print/projectprintwindow.cpp | 16 ++++++++------ 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a06bf1fde..f3bdaf9e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,26 +70,27 @@ find_package( ${QET_COMPONENTS} REQUIRED) -# Qt6 only creates the Qt::GuiPrivate target (used for QPdfEngine::drawHyperlink) -# when the GuiPrivate component is explicitly requested. Qt5 has no such -# component package and creates the target implicitly with Gui, so only -# request it on Qt6 - requesting it on Qt5 fails the whole configure. +# (QPdfEngine::drawHyperlink) needs Qt's private GUI module. +# Qt >= 6.7 ships it as a proper find_package component, but some distro +# packages (e.g. Ubuntu's qt6-base-private-dev) omit Qt6GuiPrivateConfig.cmake +# and only provide the implicit Qt6::GuiPrivate target created alongside +# Qt6::Gui. Try the component quietly, then verify the target below so a +# missing private-headers package fails here instead of at compile time. +# Qt5 has no such component — its GuiPrivate target always exists once Gui is found. if(QT_VERSION_MAJOR GREATER_EQUAL 6) - find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS GuiPrivate) + find_package(Qt6 QUIET COMPONENTS GuiPrivate) +endif() + +if(QT_VERSION_MAJOR GREATER_EQUAL 6 AND NOT TARGET Qt6::GuiPrivate) + message(FATAL_ERROR + "Qt6::GuiPrivate was not found. It is required for PDF hyperlink " + "support (). Install the Qt6 private headers " + "(e.g. 'qt6-base-private-dev' on Debian/Ubuntu) or use a Qt build " + "that provides the GuiPrivate component.") endif() find_package(SQLite3 REQUIRED) -# CMake < 4.3 only creates the SQLite::SQLite3 target (no SQLite3::SQLite3 -# alias yet), while CMake >= 4.3's bundled FindSQLite3 creates SQLite3::SQLite3 -# and deprecates the old name. Add the missing alias ourselves so we can use -# the modern target name everywhere regardless of the CMake version in use -# (this project must keep building on CMake versions below 4.3, e.g. on most -# current Linux distros). -if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3) - add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3) -endif() - set(CMAKE_AUTOUIC_SEARCH_PATHS ${QET_DIR}/sources/ui) if(QT_VERSION_MAJOR EQUAL 6) diff --git a/sources/pdf_links.cpp b/sources/pdf_links.cpp index b4ce86a5e..4e5a7d354 100644 --- a/sources/pdf_links.cpp +++ b/sources/pdf_links.cpp @@ -23,8 +23,8 @@ #include "qetgraphicsitem/element.h" #include "qetgraphicsitem/elementtextitemgroup.h" -// Private Qt PDF engine for drawHyperlink() — not public API, stable since Qt4. -// Requires QT += gui-private in qelectrotech.pro / gui-private in CMake. +// Private Qt PDF engine for drawHyperlink() — not public API. +// Availability of Qt::GuiPrivate is verified at configure time in CMakeLists.txt. #include #include diff --git a/sources/print/projectprintwindow.cpp b/sources/print/projectprintwindow.cpp index b115ad5b7..c90d71b68 100644 --- a/sources/print/projectprintwindow.cpp +++ b/sources/print/projectprintwindow.cpp @@ -28,8 +28,8 @@ #include "ui_projectprintwindow.h" -// Private Qt PDF engine for drawHyperlink() — not public API, stable since Qt4 -// Requires QT += gui-private in qelectrotech.pro +// Private Qt PDF engine for drawHyperlink() — not public API. +// Availability of Qt::GuiPrivate is verified at configure time in CMakeLists.txt. #include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove @@ -79,10 +79,14 @@ void ProjectPrintWindow::launchDialog(QETProject *project, QPrinter::OutputForma print_dialog.setWindowFlags(Qt::Sheet); #endif print_dialog.setWindowTitle(tr("Options d'impression", "window title")); - // setOptions() is the modern spelling of the Qt4-era - // setEnabledOptions() (removed in Qt 6): replace the enabled - // option set with just PrintShowPageSize, on Qt 5 and 6 alike. - print_dialog.setOptions(QAbstractPrintDialog::PrintShowPageSize); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove + print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintShowPageSize); +#else +#if TODO_LIST +#pragma message("@TODO remove code for QT 6 or later") +#endif + qDebug()<<"Help code for QT 6 or later"; +#endif if (print_dialog.exec() == QDialog::Rejected) { delete printer_; return;