0
votes

I am using a FileDialog supposedly from QtQuick.Dialogs in one of my QML files. When I open the context help in QtCreator however, it shows me the entry for FileDialog from Qt Labs, no the one from Qt Quick Dialogs as expected. I have no mention of Qt Labs anywhere in my project. Why doesn't it use the FileDialog I tell it to?

I am using QtCreator 4.6.2 with Qt 5.11.1 on Ubuntu 18.04.

Here are the relevant code snippets:

LoadFileDialog.qml:

import QtQuick 2.9
import QtQuick.Dialogs 1.3

FileDialog {
   id: loadFile

   folder: "."
   selectExisting: true
   selectMultiple: false

   title: "Please select file to load"

   onAccepted: {
     //[...]
   }

   onRejected: {
     //[...]
   }
}

Import statements in *.pro file:

QT += qml quick gui widgets
CONFIG += c++11

The application runs fine on my Ubuntu 18.04 system, from QtCreator using Qt 5.11.1 as well as stand-alone using the system's Qt 5.9. As soon as I try to run it on an Ubuntu 20.04 system with Qt 5.12 on it, it complains about not finding the FileDialog. I have no idea what library is missing to make it work either.

EDIT: The output I get when trying to run the application in Ubuntu 20.04 is:

qt5ct: using qt5ct plugin
QQmlApplicationEngine failed to load component
qrc:/main.qml:193 Type LoadFileDialog unavailable
qrc:/LoadFileDialog.qml:4 Type FileDialog unavailable
file:///usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/Dialogs/DefaultFileDialog.qml:47 module "Qt.labs.folderlistmodel" is not installed

Thanks.

1
The issue with the help being for the wrong type is likely just an issue with Creator and unrelated to your problem. What is the actual error you get when running the application on Ubuntu 20.04?Mitch
Added to original question.Sebastian
So, I found out in the meantime that the package missing on the 20.04 system was qml-module-qt-labs-folderlistmodel, since this seems to be actually imported in the DefaultFileDialog.qml of QtQuick. It turns out it got installed automatically on my 18.04 system during installation of yubikey-manager-qt which I was not aware of. Still, the file dialog looks distinctly different on both systems, on 20.04 it is nothing like the standard window manager's file dialog.Sebastian
That means that, for whatever reason, it decided to use the non-native fallback dialog. I can't remember where the logic is that decides that, but the process is described here: doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html Specifically, the part that starts with "The implementation of FileDialog will be a platform file dialog if possible."Mitch
If you would prefer (as a hopefully temporary workaround) it use a QFileDialog (aka widgets dialog) instead of the QML one, make sure your application object is a QApplication and not QGuiApplication. The logic for checking if a native dialog can be used is here: code.qt.io/cgit/qt/qtquickcontrols.git/tree/src/dialogs/…Mitch

1 Answers

1
votes

You have already figured out your original question, so I will try to answer the second one.

The logic for which type of dialog is chosen is described here:

The implementation of FileDialog will be a platform file dialog if possible. If that isn't possible, then it will try to instantiate a QFileDialog. If that also isn't possible, then it will fall back to a QML implementation, DefaultFileDialog.qml. In that case you can customize the appearance by editing this file. DefaultFileDialog.qml contains a Rectangle to hold the dialog's contents, because certain embedded systems do not support multiple top-level windows. When the dialog becomes visible, it will automatically be wrapped in a Window if possible, or simply reparented on top of the main window if there can only be one window.

This code is part of the logic that determines whether or not a native file dialog is used. This function is another part. So, to make sure you get a native file dialog, you apparently need GTK3 3.15.5 or newer. If that fails, it will fall back to a widget dialog. For that to work, your application object should also be a QApplication. Finally, a QML dialog will be used as the final fallback.