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. QFileDialog restrict for the users only the respective path
Forum Updated to NodeBB v4.3 + New Features

QFileDialog restrict for the users only the respective path

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 4.2k Views 2 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    I am using QFileDialog to save a file , i want to restrict the users to not to open any of the folders , apart from the folders which we specify in the code.

    Ex: C:/Users/Documents/QT

    and can we disable the other widgets in QFileDialog once the dialog opens, with the path specified.?.

    ```
    

    QString strFileName;

    QFileDialog oQFiledialog(this);
    oQFiledialog.setFixedSize(200,200);
    oQFiledialog.setObjectName("Hello");
    //    oQFiledialog.setFileMode(QFileDialog::ExistingFiles);
    
    strFileName = oQFiledialog.getOpenFileName(this,"","C:/Users/Documents/QT");
    
    
    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    1 Reply Last reply
    0
    • R Offline
      R Offline
      racerXali
      wrote on last edited by
      #2

      u can create a slot like dirchanged(QString dir), connect your file dialog's current changed signal to it :

      connect(m_Fdialog,SIGNAL(currentChanged(QString)),SLOT(dirchanged(QString)));
      

      and set the directory back to your desired path:

      void Dialog::dirchanged(QString dir)
       {
           m_Fdialog->setDirectory("<your specific DIR path>");
       }
      

      this way you'll always end up in the same directory.

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hung Tran
        wrote on last edited by
        #3

        I can use:
        QFileDialog dialog(this);
        connect(&dialog, SIGNAL(directoryEntered(const QString &)), this, SLOT(onFileDialogDirectoryChanged(const QString &)));

        1 Reply Last reply
        0
        • R Offline
          R Offline
          racerXali
          wrote on last edited by
          #4

          u can create a slot like dirchanged(QString dir), connect your file dialog's current changed signal to it :
          connect(m_Fdialog,SIGNAL(currentChanged(QString)),SLOT(dirchanged(QString)));
          and set the directory back to your desired path:
          void Dialog::dirchanged(QString dir)
          {
          m_Fdialog->setDirectory("<your specific DIR path>");
          }
          this way you'll always end up in the same directory.

          @Hung-Tran yours is better so i changed mine

          connect(m_Fdialog,SIGNAL(directoryEntered(QString)),SLOT(dirchanged(QString)));
          void Dialog::dirchanged(QString dir)
           {
               m_Fdialog->setDirectory("<your specific DIR path>");
           }
          
          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