Important: Please read the Qt Code of Conduct -

Set a default UNC path for QFileDialog

  • I wanted to open QFileDialog with a specific path like: //Machine/C$/Users/. I have implemented the following function but it doesn't work.

    void DownloadFM::on_pushButtonSource_clicked()
        QFileDialog o_dialogSource;
        QString fileName = QFileDialog::getOpenFileName(this, "Choose File");

  • @Azadshahr
    I am not sure Qt file dialogs/operations support UNCs.

  • So what should I do now?

  • @Azadshahr
    Before proceeding: It would be nice to see a qDebug() << absolutePath. I have done enough support in this forum to know that when questioners say something like " with a specific path like: //Machine/C$/Users/" it can turn out that is not actually what they are passing....

    Furthermore, how do I know whether your app is running with sufficient privilege to read \\Machine\C$, which is an administrative share? Have you tried other UNC shares, non-Administrative?

    Finally, all you have said is " following function but it doesn't work". What exactly does "doesn't work" mean? Where does the file dialog place you if the UNC is not accepted?

  • Sorry, I should describe it more. However, I have a program which is works with the file system pretty well. I can create file/directory, rename file/directory, delete file/directory, and so on but when I wanted to move a directory to another place with using QDir::rename, it returns false to me. I give to this function two-path i.e. //Machinex64/C$/Users/FolderSample1 and //Machinex64/C$/Users/FolderSample2. When this function executed, it can't move the directory. Also, I give to application administrative privilege.

  • @Azadshahr
    For my part, I cannot see any relation to whatever you are saying in your last post and setting a UNC path in a QFileDialog. If you have some application privilege issue you should deal with that separately from a UNC issue.

  • Lifetime Qt Champion

    So you can read/create files etc in //Machinex64/C$/Users/FolderSample2 ?
    its ONLY the QDir::rename that fails ?

Log in to reply