Important: Please read the Qt Code of Conduct -

How to get return path from a customized QFileDialog widget

  • I have created a custom QFileDialog widget with the following properties. Now, I wanted when it is executing and a file selected, I can get the path. How should I do that?

    QList<QUrl> sharedDriveBasedSMB;
    sharedDriveBasedSMB << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath());

    QFileDialog o_dialogSource;
    o_dialogSource.getOpenFileName(this, "Choose File");

    QFileDialog will executed but I wanted to get the file path too. I don't know how should I do that. I wanted a result like the following:

    QString path = QFileDialog(...);

    But I don't know in a customized QFileDialog how should I introduced path variable to it.

  • Lifetime Qt Champion

  • @Christian-Ehrlicher I have used the following code, but when QMessageBox executed it shows just an empty string to me. Where is the problem?

    QString fileName;
    QFileDialog dialog;
    QList<QUrl> drives;
    drives << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath());
    QMessageBox::information(this, "Message", fileName);

  • Lifetime Qt Champion


    You are calling the wrong function. It's selectedUrls as @Christian-Ehrlicher linked.

  • @Azadshahr
    And additionally you need to get the selectedUrls() after executing the dialog, not before!

Log in to reply