Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get return path from a customized QFileDialog widget
Forum Updated to NodeBB v4.3 + New Features

How to get return path from a customized QFileDialog widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 400 Views 1 Watching
  • 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.
  • AzadshahrA Offline
    AzadshahrA Offline
    Azadshahr
    wrote on last edited by
    #1

    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.setOption(QFileDialog::DontUseNativeDialog);
    o_dialogSource.setSidebarUrls(sharedDriveBasedSMB);
    o_dialogSource.getOpenFileName(this, "Choose File");
    o_dialogSource.exec();
    

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See QFileDialog::selectedUrls()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      AzadshahrA 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        See QFileDialog::selectedUrls()

        AzadshahrA Offline
        AzadshahrA Offline
        Azadshahr
        wrote on last edited by
        #3

        @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;
        dialog.setOption(QFileDialog::DontUseNativeDialog);
        
        QList<QUrl> drives;
        drives << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath());
        dialog.setSidebarUrls(drives);
        dialog.selectUrl(fileName);
        dialog.exec();
        
        QMessageBox::information(this, "Message", fileName);
        
        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • AzadshahrA Azadshahr

            @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;
            dialog.setOption(QFileDialog::DontUseNativeDialog);
            
            QList<QUrl> drives;
            drives << QUrl::fromLocalFile(QDir("//DC1/C$/Users/").absolutePath());
            dialog.setSidebarUrls(drives);
            dialog.selectUrl(fileName);
            dialog.exec();
            
            QMessageBox::information(this, "Message", fileName);
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

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

            1 Reply Last reply
            2

            • Login

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