2

I am doing an App in QML / QT / C++ (to train myself for an internship). I need to open a FileDialog in order to choose a folder location but I get an error when writing the line selectFolder: true.

I found this property here https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#selectFolder-prop

It's weird because I can't set selectExisting and selectMultiple either.

The documentation said we have to specify these before opening the Dialog. I did this, I don't understand.

Can anyone help me fix this error ?

Here is what I import in main.qml: import QtQuick.Dialogs 1.3

Thank you very much. Have a good day.

Here is the code:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3


Window {
        id: mainWindow
        visible: true

        width: 700
        height: 500

        // FileDialog
        FileDialog {
            id: fileDialog
            title: "Please choose a file"
            folder: shortcuts.home
            selectFolder: true
            onAccepted: {
                console.log("You chose: " + fileDialog.fileUrls)
                //acceptDialog();
            }
            onRejected: {
                console.log("rejected")
                //rejectDialog();
            }
            Component.onCompleted: visible = true
        }

}

It's not the entire code (+ 200 lines) Image from Qt Creator

fallous
  • 31
  • 6
  • Show us more of the code. (FWIW, you're actually asking about QML, not straight up C++. If you are working in just C++, the answer will be different.) – metal May 19 '20 at 15:19
  • I am sorry, I imported an image but it did not appears. I am figuring out how to share an image here. Im am working with QML for front end but C++ for back-end – fallous May 19 '20 at 15:24
  • You should copy-paste the text of the code right into the question. Pasting an image is less helpful because we then need to re-type it if we want to try it out ourselves. – metal May 19 '20 at 15:25
  • It's done. I just came to see the edit button – fallous May 19 '20 at 15:41

2 Answers2

1

For me, the code worked fine. Just try to delete and then put the line again. Sometimes qml gives you these kinds of errors for no reason. Just try to run it. If there are some errors, post them

Marco Medri
  • 176
  • 3
  • I did it many times but I still get the error like the picture I Posted, I don't understand "It's not the entire code (+ 200 lines) Image from Qt Creator" – fallous May 20 '20 at 11:50
1

I resolved the problem.

My Qt Project version was 5.12, I created a new project with Qt 5.14 and it worked. Thanks.

fallous
  • 31
  • 6