Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuickControls FileDialog Automation
Forum Updated to NodeBB v4.3 + New Features

QtQuickControls FileDialog Automation

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 242 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SamBob
    wrote on last edited by
    #1

    I'm trying to automate picking a file in QML in a QtQuick Controls FileDialog. How can I invoke FileDialog's accept with a specific fileUrl when the fileUrl property is read only?

    The current attempt involves calling filedialog.clearSelection, filedialog.addSelection and finally filedialog.accept. clearSelection and addSelection are not documented but can be found in source https://github.com/qt/qtquickcontrols/blob/dev/src/dialogs/qquickfiledialog.cpp (Assuming Qt has used a DefaultFileDialog as this can be system dependent)

    However clearSelection seems to only work sporadically, having no affect if the same FileDialog has been used manually, hence the addSelection fails to set fileUrl.

    The following is a QML file (loaded as a basic project within QtCreator) demonstrating this. with a manual file dialog open button and an automatic one:

    import QtQuick 2.9
    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.4
    import QtQuick.Dialogs 1.3
    
    Window {
        visible: true;width: 200;height:200
        FileDialog {id: filedialog; onAccepted: console.log("File Dialog Accepted: ", fileUrl, fileUrls);}
        Row {
            Button {text: "manual"; onClicked: filedialog.open()}
            Button {
                text: "auto_qml"
                onClicked: {
                    console.log("Current selection:", filedialog.fileUrl, filedialog.fileUrls)
                    filedialog.clearSelection();
                    console.log("cleared selection:", filedialog.fileUrl, filedialog.fileUrls) // only clears selection if manual not used
                    let t = filedialog.addSelection("file:/home/user/tempfile.txt");
                    console.log("add selection success:", t) // a non existent file returns false, so file must exist
                    filedialog.accept()
                }
            }
        }
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved