Bug 467631

Summary: kguiaddons fails to build with qt6/kde6
Product: [Frameworks and Libraries] frameworks-kguiaddons Reporter: kdebug
Component: generalAssignee: kdelibs bugs <kdelibs-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: borgman.jeremy, mrp, randomland
Priority: NOR    
Version First Reported In: 6.17.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description kdebug 2023-03-20 22:56:37 UTC
SUMMARY
When running "kdesrc-build frameworks" (after: changing all configs to target kf6-qt6 and building qt6 from source), compilation fails (even though dependency checks seem to succeed).

STEPS TO REPRODUCE
1. On debian testing, setup kdesrc-build according to: https://community.kde.org/Get_Involved/development and modify configs according to (in order to build qt6 & target qt6/kde6): https://community.kde.org/Get_Involved/development/More#Build_Qt6_using_kdesrc-build
2. Run "kdesrc-build qt6-set" to build and install qt6.
3. Reconfigure kdesrc-buildrc to build kf6 and plasma (instead of qt6)
4. Run "kdesrc-build frameworks"

OBSERVED RESULT
At step 11/79 of kdesrc-build frameworks ("Building kguiaddons from frameworks (11/79)") , kdesrc-build outputs "Compiling... failed (after 1 second)            kguiaddons didn't build, stopping here.". Inspecting the error.log output of kguiaddons gives us:

# kdesrc-build running: 'gmake' '-j' '16'
# from directory: /home/jj/kde/build/kguiaddons
[  0%] Automatic MOC for target kgeourihandlertest
[  0%] Automatic MOC for target kde-geo-uri-handler
[  0%] Automatic MOC for target KF6GuiAddons
[  0%] Built target kgeourihandlertest_autogen
[  0%] Built target kde-geo-uri-handler_autogen
[ 13%] Built target KF6GuiAddons_autogen
[ 16%] Built target kgeourihandlertest
[ 20%] Built target kde-geo-uri-handler
[ 21%] Building CXX object src/CMakeFiles/KF6GuiAddons.dir/util/kmodifierkeyinfoprovider_xcb.cpp.o
/home/jj/kde/src/kguiaddons/src/util/kmodifierkeyinfoprovider_xcb.cpp: In function ‘Display* display()’:
/home/jj/kde/src/kguiaddons/src/util/kmodifierkeyinfoprovider_xcb.cpp:58:55: error: ‘QX11Application’ is not a member of ‘QNativeInterface’
   58 |     return qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
      |                                                       ^~~~~~~~~~~~~~~
/home/jj/kde/src/kguiaddons/src/util/kmodifierkeyinfoprovider_xcb.cpp:58:71: error: no matching function for call to ‘QGuiApplication::nativeInterface<<expression error> >()’
   58 |     return qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
      |                                                                       ^
In file included from /home/jj/kde/usr/include/QtCore/qcoreapplication.h:16,
                 from /home/jj/kde/usr/include/QtGui/qguiapplication.h:8,
                 from /home/jj/kde/usr/include/QtGui/QGuiApplication:1,
                 from /home/jj/kde/src/kguiaddons/src/util/kmodifierkeyinfoprovider_xcb.cpp:11:
/home/jj/kde/usr/include/QtGui/qguiapplication.h:140:5: note: candidate: ‘template<class NativeInterface, class TypeInfo, class BaseType, typename std::enable_if<TypeInfo::isCompatibleWith<QGuiApplication>, bool>::type <anonymous> > NativeInterface* QGuiApplication::nativeInterface() const’
  140 |     QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QGuiApplication)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jj/kde/usr/include/QtGui/qguiapplication.h:140:5: note:   template argument deduction/substitution failed:
/home/jj/kde/src/kguiaddons/src/util/kmodifierkeyinfoprovider_xcb.cpp:58:71: error: template argument 1 is invalid
   58 |     return qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
      |                                                                       ^
gmake[2]: *** [src/CMakeFiles/KF6GuiAddons.dir/build.make:610: src/CMakeFiles/KF6GuiAddons.dir/util/kmodifierkeyinfoprovider_xcb.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:269: src/CMakeFiles/KF6GuiAddons.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2


EXPECTED RESULT
Kguiaddons successfully builds with no errors.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian Testing with kdesrc-build targeting kf6-qt6 (Latest Master/Main branch)

ADDITIONAL INFORMATION
Attempts to use the default qt6 packages shipped by debian testing have also failed when using "kdesrc-build frameworks" at kwayland. It seems that qt6 as shipped by debian testing is not complete for development (even if all development packages are installed).
Comment 1 randomland 2023-06-26 12:07:12 UTC
I am hitting the same error on Pop 22.04 with Qt compiled via kdesrc-build. How did you solve that?
Comment 2 kdebug 2023-06-26 12:28:10 UTC
I could not resolve this issue. I did try to talk to a KDE contributor, however, their only recommendation was to use kde/qt 5 and ignore kde/qt 6. Hence, I'm not interested in pursuing kde contributions or this issue any further.
Comment 3 Mark Penner 2023-09-15 02:28:43 UTC
I ran into this also with Qt 6.6 compiled with kdesrc-build on Debian unstable. To fix it I needed to add `-DQT_FEATURE_xcb=ON` to `cmake-options` and rebuild qt6-set (I'm not sure if rebuilding only qtbase would have been enough, so I built it all). I added it in `~/kde/src/kdesrc-build/qt6-build-include` but I think you could use `kdesrc-build qt6-set --cmake-options="-DQT_FEATURE_xcb=ON"` like it says on https://community.kde.org/Get_Involved/development/More#Build_Qt6_using_kdesrc-build, near the end of the section.

I tried to find where QX11Application was defined, and I found https://invent.kde.org/qt/qt/qtbase/-/blob/6.6/src/gui/kernel/qguiapplication_platform.h?ref_type=heads#L41 in a `#if QT_CONFIG(xcb) || defined(Q_QDOC)` block. I'm not familiar with the Qt codebase and all the macros, but that's what made me try setting `-DQT_FEATURE_xcb=ON`, and kguiaddons compiled fine after rebuilding Qt.
Comment 4 Jeremy 2025-08-10 00:28:22 UTC
Flameshot uses KSystemClipboard provided by KGuiAddons. After porting to Qt6 our clipboard functionality stopped working on gnome + wayland. This error is reported:

```
kf.guiaddons: Could not init WaylandClipboard, falling back to QtClipboard.
```

I then wrote a very minimal working example to demonstrate this bug. If this code is executed on Gnome + Wayland the same error is printed to the terminal. Unfortunately falling back to QtClipboard does not work on gnome + wayland. Is this user error on my part with how we are using the clipboard or is there an underlying issues?

```
#include <QApplication>
#include <KSystemClipboard>
#include <QDebug>
#include <QGuiApplication>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    auto clipboard = KSystemClipboard::instance();
    if (!clipboard) {
        qDebug() << "Failed to get KSystemClipboard instance";
        return 1;
    }

    qDebug() << "KSystemClipboard initialized successfully";
    return 0;
}
```
Comment 5 Jeremy 2025-08-10 00:29:33 UTC
I'm sorry I meant to post my comment as a new bug not a comment here and I cant figure out how to delete it. Apologies.