Filedialog problem in QML

Asked

Viewed 28 times

1

I’m trying to use the component FileDialog in the QML

I made exactly the same code that is in the Qt documentation on the link http://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html and this code did not show the FileDialog and returned the error: QFileInfo::absolutePath: Constructed with empty filename. I tried writing a simple code to test, but the same error occurred. My code is below:

import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2

Window {
    visible: true

    width: 360
    height: 640

    maximumHeight: 640
    minimumHeight: 640

    maximumWidth: 360
    minimumWidth: 360

    title: "Acessar Galeria Test"

    Rectangle {
        id: principal

        anchors.fill: parent

        FileDialog {
            id: fileDialog

            title: "Please choose a file"

            folder: shortcuts.home

            visible: true
        }
    }
}

1 answer

1


To propriedade visible of FileDialog cannot be true as long as the component is not complete, so use Component.onComplete to define the FileDialog as true. So the code must stay this way to work:

import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2

Window {
    visible: true

    width: 360
    height: 640

    maximumHeight: 640
    minimumHeight: 640

    maximumWidth: 360
    minimumWidth: 360

    title: "Acessar Galeria Test"

    Rectangle {
        id: principal

        anchors.fill: parent

        FileDialog {
            id: fileDialog

            title: "Please choose a file"

            folder: shortcuts.home

            visible: false
        }
    }

    Component.onCompleted: {
        fileDialog.visible = true;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.