关于使用Qt.labs.platform在arch中报错 ERROR: No native FileDialog implementation available.的原因记录

发布时间 2023-07-30 11:53:20作者: 凡璞

当跟着Qt Book的章节QtQuick Controls编写一个ImageViewer,运行时报错:

ERROR: No native FileDialog implementation available.
Qt Labs Platform requires Qt Widgets on this setup.
Add 'QT += widgets' to .pro and create QApplication in main().

尝试过搜索在cmake中引入QWidgets模块,但是无济于事,还是报错。
在google的一段时间无果后,还是回到了官方文档去查看缘由。最终发现了原因:
在官方文档的Qt.labs.platform下面写明了:

A native platform file dialog is currently available on the following platforms:

- Android
- iOS
- Linux (when running with the GTK+ platform theme)
- macOS
- Windows

The Qt Labs Platform module uses Qt Widgets as a fallback on platforms that do not have a native implementation available. Therefore, applications that use types from the Qt Labs Platform module should link to QtWidgets and use QApplication instead of QGuiApplication.

在linux平台只有GTK+的平台才提供了native实现。而我用的是KDE,所以不行。

在KDE中可以使用Quick.Dialog中的FileDialog去实现想要的功能,不过界面可能并不是很美观


还得多看文档!!!!!