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. Open UNC path as default in QFileDialog
Forum Updated to NodeBB v4.3 + New Features

Open UNC path as default in QFileDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 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 Azadshahr
    #1

    I wanted to open QFileDialog for a specific path like //DC1/C$/Users/ but when QFileDialog opens it goes to a default path. When QFileDialog opens, I can change directory to the UNC path but I wanted to open this path as default. How can I do that? In the following code, g_absolutePath has been initialized with //DC1/C$/Users/ but it doesn't work.

    #include "uploadfm.h"
    #include "ui_uploadfm.h"
    
    #include "mainwindow.h"
    
    UploadFM::UploadFM(QWidget *parent) : QMainWindow(parent), ui(new Ui::UploadFM)
    {
        ui->setupUi(this);
        QWidget::setFixedSize(600, 175);
    }
    
    UploadFM::~UploadFM()
    {
        delete ui;
    }
    
    void UploadFM::on_pushButtonSource_clicked()
    {
        QString fileName = QFileDialog::getOpenFileName(this, "Choose File", g_absolutePath);
    
        if(fileName.isEmpty())
            return;
    
        ui->lineEditSourcePath->setText(fileName);
    }
    
    void UploadFM::on_pushButtonDestination_clicked()
    {
        QString fileName = QFileDialog::getExistingDirectory(this, "Choose Folder", g_absolutePath);
    
        if(fileName.isEmpty())
            return;
    
        ui->lineEditDestinationPath->setText(fileName);
    }
    
    void UploadFM::on_pushButtonUpload_clicked()
    {
        QString l_sourceFileName = ui->lineEditSourcePath->text();
        QString l_destinationFileName = ui->lineEditDestinationPath->text();
    
        if(l_sourceFileName.isEmpty() || l_destinationFileName.isEmpty())
            return;
    
        QFile file(l_sourceFileName);
    
        if(file.copy(l_destinationFileName))
        {
            statusBar()->showMessage("Upload has been Successful ... ");
        }
        else
        {
            statusBar()->showMessage("Upload has failed ...");
        }
    }
    
    JonBJ 1 Reply Last reply
    0
    • AzadshahrA Azadshahr

      I wanted to open QFileDialog for a specific path like //DC1/C$/Users/ but when QFileDialog opens it goes to a default path. When QFileDialog opens, I can change directory to the UNC path but I wanted to open this path as default. How can I do that? In the following code, g_absolutePath has been initialized with //DC1/C$/Users/ but it doesn't work.

      #include "uploadfm.h"
      #include "ui_uploadfm.h"
      
      #include "mainwindow.h"
      
      UploadFM::UploadFM(QWidget *parent) : QMainWindow(parent), ui(new Ui::UploadFM)
      {
          ui->setupUi(this);
          QWidget::setFixedSize(600, 175);
      }
      
      UploadFM::~UploadFM()
      {
          delete ui;
      }
      
      void UploadFM::on_pushButtonSource_clicked()
      {
          QString fileName = QFileDialog::getOpenFileName(this, "Choose File", g_absolutePath);
      
          if(fileName.isEmpty())
              return;
      
          ui->lineEditSourcePath->setText(fileName);
      }
      
      void UploadFM::on_pushButtonDestination_clicked()
      {
          QString fileName = QFileDialog::getExistingDirectory(this, "Choose Folder", g_absolutePath);
      
          if(fileName.isEmpty())
              return;
      
          ui->lineEditDestinationPath->setText(fileName);
      }
      
      void UploadFM::on_pushButtonUpload_clicked()
      {
          QString l_sourceFileName = ui->lineEditSourcePath->text();
          QString l_destinationFileName = ui->lineEditDestinationPath->text();
      
          if(l_sourceFileName.isEmpty() || l_destinationFileName.isEmpty())
              return;
      
          QFile file(l_sourceFileName);
      
          if(file.copy(l_destinationFileName))
          {
              statusBar()->showMessage("Upload has been Successful ... ");
          }
          else
          {
              statusBar()->showMessage("Upload has failed ...");
          }
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Azadshahr
      Ther's no point rasing a new duplicate of your https://forum.qt.io/topic/116104/set-a-default-unc-path-for-qfiledialog. Whatever answers will be there, and that has more information than here anyway. How does this differ?

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Please continue your other thread. This one will be locked.

        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