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. Getting proper folder path
QtWS25 Last Chance

Getting proper folder path

Scheduled Pinned Locked Moved Solved General and Desktop
qt creatorfolder pathbuttonline edit
5 Posts 2 Posters 3.6k Views
  • 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

    In my qt c++ application when the button is clicked the file dialog opens and when the select folder button in the file dialog is clicked the folder path is to be taken to the line edit in my application. But though the folder path appears the current folder does not appear at the end!
    following is my code
    void MainWindow::on_Button_clicked()
    {
    QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
    QDir d = QFileInfo(Filepath).absoluteDir();
    QString absolute=d.absolutePath();
    ui->Path->setText(absolute);

        }
    

    If the current folder is B and the parent folder is A(which is on the desktop) it should depict "Desktop/A/B" on the line edit but currently it shows only "Desktop/A"!
    How can i correct this issue?

    J.HilkJ 1 Reply Last reply
    0
    • L Lasith

      In my qt c++ application when the button is clicked the file dialog opens and when the select folder button in the file dialog is clicked the folder path is to be taken to the line edit in my application. But though the folder path appears the current folder does not appear at the end!
      following is my code
      void MainWindow::on_Button_clicked()
      {
      QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
      QDir d = QFileInfo(Filepath).absoluteDir();
      QString absolute=d.absolutePath();
      ui->Path->setText(absolute);

          }
      

      If the current folder is B and the parent folder is A(which is on the desktop) it should depict "Desktop/A/B" on the line edit but currently it shows only "Desktop/A"!
      How can i correct this issue?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Lasith hi,

      I don't quite understand why you go the detour over QFileInfo,

      this, should do exactly what you want to happen

      void MainWindow::on_Button_clicked()
      {
         QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
          ui->Path->setText(Filepath);
      }
      

      However if you insist on the useage QFileInfo, try it with QString QFileInfo::absoluteFilePath()

      void MainWindow::on_Button_clicked()
      {
         QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
          QDir d = QFileInfo(Filepath).absoluteDir();
          QString absolute=d.absoluteFilePath();
          ui->Path->setText(absolute);
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      L 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @Lasith hi,

        I don't quite understand why you go the detour over QFileInfo,

        this, should do exactly what you want to happen

        void MainWindow::on_Button_clicked()
        {
           QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
            ui->Path->setText(Filepath);
        }
        

        However if you insist on the useage QFileInfo, try it with QString QFileInfo::absoluteFilePath()

        void MainWindow::on_Button_clicked()
        {
           QString Filepath = QFileDialog::getExistingDirectory(this, "Get Any File");
            QDir d = QFileInfo(Filepath).absoluteDir();
            QString absolute=d.absoluteFilePath();
            ui->Path->setText(absolute);
        }
        
        L Offline
        L Offline
        Lasith
        wrote on last edited by
        #3

        @J-Hilk Your code gives the method to get a file path but I need the folder path! my code works but does not show current folder in the absoulte path :(

        J.HilkJ 1 Reply Last reply
        0
        • L Lasith

          @J-Hilk Your code gives the method to get a file path but I need the folder path! my code works but does not show current folder in the absoulte path :(

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Lasith

          Taken from here:

          QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"
          

          Pretty much what you want to happen, as far as I understand it


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          L 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @Lasith

            Taken from here:

            QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"
            

            Pretty much what you want to happen, as far as I understand it

            L Offline
            L Offline
            Lasith
            wrote on last edited by
            #5

            @J.Hilk Thanx mate :) I had been too complex

            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