xiaoyifang / goldendict-ng

The Next Generation GoldenDict
https://xiaoyifang.github.io/goldendict-ng/
Other
1.68k stars 93 forks source link

Error: ‘QX11Application’ is not a member of ‘QNativeInterface #1471

Open GuShaocheng opened 6 months ago

GuShaocheng commented 6 months ago

Describe the bug I can't complete cmake build. Errors were pointed to QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();

For example, /goldendict-ng-24.01.22-LoongYear.3dddb3be/goldendict-ng-24.01.22-LoongYear.3dddb3be/src/hotkeywrapper.cc: In member function ‘quint32 HotkeyWrapper::nativeKey(int)’: /goldendict-ng-24.01.22-LoongYear.3dddb3be/goldendict-ng-24.01.22-LoongYear.3dddb3be/src/hotkeywrapper.cc:815:21: error: ‘QX11Application’ is not a member of ‘QNativeInterface’; did you mean ‘QWaylandApplication’? 815 | QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >(); | ^~~~~~~~~~~~~~~ | QWaylandApplication /goldendict-ng-24.01.22-LoongYear.3dddb3be/goldendict-ng-24.01.22-LoongYear.3dddb3be/src/hotkeywrapper.cc:815:39: error: ‘x11AppInfo’ was not declared in this scope 815 | QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >(); | ^~~~~~~~~~ /goldendict-ng-24.01.22-LoongYear.3dddb3be/goldendict-ng-24.01.22-LoongYear.3dddb3be/src/hotkeywrapper.cc:815:93: error: ‘QX11Application’ is not a member of ‘QNativeInterface’; did you mean ‘QWaylandApplication’? 815 | ion * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >(); | ^~~~~~~~~~~~~~~ | QWaylandApplication /goldendict-ng-24.01.22-LoongYear.3dddb3be/goldendict-ng-24.01.22-LoongYear.3dddb3be/src/hotkeywrapper.cc:815:110: error: no matching function for call to ‘QApplication::nativeInterface<<expression error> >()’ 815 | AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >(); | ^

To Reproduce Steps to reproduce the behavior:

  1. download source code
  2. cd goldendict-ng && mkdir build_dir
  3. cmake -S . -B build_dir \ --install-prefix=/usr/local/ \ -DCMAKE_BUILD_TYPE=Release
  4. cmake --build build_dir --parallel after [100%], I see errors. All are related to QX11Application as mentioned before.

OS and software versions Ubuntu 22.04 cmake 3.29.1 qt6 6.5.4

xiaoyifang commented 3 months ago

wayland?

OldCoder commented 3 months ago
I had the error that is discussed in this thread: **Error: 'QX11Application' is not a member of 'QNativeInterface'** I was able to find the cause, or what had caused it for me, and to fix it. "goldendict-ng" has acquired an indirect dependency on a package with the official upstream name "xcb-util-cursor". Note: The distro-level name of the package may vary from distro to distro. By indirect, I mean that "goldendict-ng" requires a version of "qt6" that was built with "xcb-util-cursor" support. **For "goldendict-ng" to build:** If you build "qt6" yourself, the development version of "xcb-util-cursor" needs to be built or installed first. If you use a distro "qt6" package, "xcb-util-cursor" needs to be installed before you build "goldendict-ng". I work on my own distro. So, I build everything. I built "xcb-util-cursor" and rebuilt "qt6". I was then able to build "goldendict-ng". A screenshot of the result is attached below. ![goldendict-240723](https://github.com/user-attachments/assets/ec6c8371-68dc-432a-bd5a-cad90ddb14dc) Note: My distro site is: https://laclin.com/ **Notes to the "goldendict-ng" lead:** I was forced to switch to "-ng" because the original "goldendict" requires "qtwebkit" as opposed to "qtwebengine" and "qtwebkit" is now impossible to build. This meant that I had to get "qt6" to build because "-ng" no longer supports "qt5". This was interesting because it was nearly impossible to get "qt6" to build. However, I spent a week on it just so that I could have "goldendict-ng". One other point: "goldendict-ng" refuses to run for the "root" user. To make this work, I need to do some tricks. It would be nice if the restriction could be removed.
xiaoyifang commented 3 months ago

One other point: "goldendict-ng" refuses to run for the "root" user. To make this work, I need to do some tricks. It would be nice if the restriction could be removed.

gd-ng should has no restriction on root user.

Bro-Account commented 3 months ago

I had the error that is discussed in this thread: Error: 'QX11Application' is not a member of 'QNativeInterface'

Hi and sorry for the OT, but I'm dealing with the same issue in another product: https://github.com/martinrotter/rssguard/discussions/1338 I tried installing the mentioned package, but I am unable to find it. Could you maybe help me out? Thank you!

shenlebantongying commented 3 months ago

tldr: it appears that Qt now days can be built without xcb/xlib support.

Ubuntu 22.04 cmake 3.29.1 qt6 6.5.4

No idea how is this version of Qt is installed, but it is not the one from ubuntu's repo.

I also have no idea about how Qt automatically detecting things.

However, adding -DQT_FEATURE_XCB=ON when building Qt should resolve the problem.

@OldCoder's discovery is right, installing certain libraries will enable xcb feature automatically.

@Bro-Account is a similar but different issue. QWaylandApplication comes from wayland feature, -DQT_FEATURE_wayland=ON is needed when building Qt.

Related code:

QX11Application needs xcb feature enabled and QWaylandApplication need wayland feature enabled. https://github.com/qt/qtbase/blob/02cb165ef8050230b477358e4136e9f0acd83eb6/src/gui/kernel/qguiapplication_platform.h#L56-L67

Qt's CMake code that enables those features.

xcb https://github.com/qt/qtbase/blob/02cb165ef8050230b477358e4136e9f0acd83eb6/src/gui/configure.cmake#L944-L949

wayland https://github.com/qt/qtbase/blob/02cb165ef8050230b477358e4136e9f0acd83eb6/src/gui/configure.cmake#L1263-L1267

shenlebantongying commented 3 months ago

We need a compile time flag to disable all things that depend on X/X11/xcb based on /usr/include/qt6/QtGui/qtgui-config.h -> QT_FEATURE_xcb