gui icon indicating copy to clipboard operation
gui copied to clipboard

QFileDialog fails to use platform-native dialog if static linked

Open hebasto opened this issue 5 years ago • 11 comments

While investigating #32 I found a buggy (?) behavior of QFileDialog.

From the Qt docs:

By default, a platform-native file dialog will be used if the platform has one.

When Qt and QPA plugin are dynamic linked:

$ ./src/qt/bitcoin-qt -printtoconsole
2020-07-15T09:15:39Z [main] Bitcoin Core version v0.20.0 (release build)
2020-07-15T09:15:39Z [main] Qt 5.12.8 (dynamic), plugin=xcb (dynamic)

QFileDialog works as expected, and uses a platform-native file dialog.


When Qt and QPA plugin are static linked (gitian builds):

$ /home/hebasto/bitcoin-0.20.0/bin/bitcoin-qt -printtoconsole
2020-07-15T09:07:04Z Bitcoin Core version v0.20.0 (release build)
2020-07-15T09:07:04Z Qt 5.9.8 (static), plugin=xcb (static)

QFileDialog fails to recognize the platform, and uses a widget-based implementation.

Even running with QT_QPA_PLATFORM=xcb doesn't help.

hebasto avatar Jul 15 '20 09:07 hebasto

https://forum.kde.org/viewtopic.php?t=90626#p172050:

In order to use the native KDE file dialog, you need to link to Qt dynamically.

https://forum.kde.org/viewtopic.php?t=90626#p172100:

This is a limitation in Qt, not KDE. Qt cannot guarantee that plugin loading works on all platforms when being linked statically.

Especially not when the plugin is linked against a different version of Qt.

Could be related:

  • https://bugreports.qt.io/browse/QTBUG-14138
  • https://bugreports.qt.io/browse/QTBUG-14246

hebasto avatar Jul 15 '20 09:07 hebasto

So why is the widget based dialog unable to detect any folders?

maflcko avatar Jul 15 '20 09:07 maflcko

So why is the widget based dialog unable to detect any folders?

That is the question in #32, and I'm still working on it :)

This issue differs from #32.

hebasto avatar Jul 15 '20 09:07 hebasto

Nice find!

ryanofsky avatar Jul 15 '20 09:07 ryanofsky

@MarcoFalke

So why is the widget based dialog unable to detect any folders?

A: https://github.com/bitcoin/bitcoin/pull/19536

hebasto avatar Jul 16 '20 17:07 hebasto

UPDATE: such behavior observed on Linux only.

Static builds work fine on Windows (tested Windows 10) and macOS (tested macOS 10.15.6).

hebasto avatar Aug 09 '20 18:08 hebasto

UPDATE: such behavior observed on Linux only.

~~I thought this was fixed by https://github.com/bitcoin/bitcoin/pull/19536?~~

This change partially reverts 248e22b (#16386) and makes QFileDialogs work again for static builds. Fixes bitcoin-core/gui#32.

Right, I see these are separate.

fanquake avatar Aug 10 '20 05:08 fanquake

$ make -C depends
make: Entering directory '/home/hebasto/guix/GitHub/bitcoin/depends'
Extracting qt...
/home/hebasto/guix/GitHub/bitcoin/depends/sources/qtbase-opensource-src-5.9.8.tar.xz: OK
/home/hebasto/guix/GitHub/bitcoin/depends/sources/qttranslations-opensource-src-5.9.8.tar.xz: OK
/home/hebasto/guix/GitHub/bitcoin/depends/sources/qttools-opensource-src-5.9.8.tar.xz: OK
Preprocessing qt...
...
Configuring qt...
Creating qmake...
...
Done running configuration tests.

Configure summary:
...
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows
...

@theuni Could missed GTK+ support cause this bug?

hebasto avatar Aug 10 '20 16:08 hebasto

This @laanwj's comment is old enough but seems related:

As I've said before many times, I'm not happy about statically linking qt on Linux - and certainly not everything it depends on like font libraries. This should be up to the system. This will mess up appmenu integration in Ubuntu, for example, and other distro-specific customization.

hebasto avatar Aug 11 '20 19:08 hebasto

Could missed GTK+ support cause this bug?

It seems missed GTK+ support does not cause this bug. I've configured and compiled static Qt with

Qt Widgets:
  GTK+ ................................... yes
  Styles ................................. Fusion Windows

then compiled bitcoin-qt with statically linked Qt:

$ ldd src/qt/bitcoin-qt | grep -i qt
# empty output
$ src/qt/bitcoin-qt -regtest -printtoconsole
2020-08-12T11:25:36Z [main] Bitcoin Core version v0.20.99.0-7c8e2ecf0 (release build)
2020-08-12T11:25:36Z [main] Qt 5.9.8 (static), plugin=xcb (static)
2020-08-12T11:25:36Z [main] System: Linux Mint 20, x86_64-little_endian-lp64
2020-08-12T11:25:36Z [main] Screen: HDMI-2 1600x1200, pixel ratio=1.0
...

and a widget-based QFileDialog is still openning.

hebasto avatar Aug 12 '20 11:08 hebasto

Here is another observation. A non-native QFileDialog requires ICU support, but it is disabled: https://github.com/bitcoin-core/gui/blob/7317e14a44c6efc545e6fb9bcedee7174e93a8fa/depends/packages/qt.mk#L40

As a consequence, users experience Qt warnings every time they open a filesystem dialog:

2021-06-23T15:48:26Z GUI: Case insensitive sorting unsupported in the posix collation implementation
2021-06-23T15:48:26Z GUI: Numeric mode unsupported in the posix collation implementation

Just removing -no-icu is not an option as it introduces new dependencies and exported symbols.

hebasto avatar Jun 24 '21 04:06 hebasto