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

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 25 Oct 2017, 09:46 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 1 Reply Last reply 25 Oct 2017, 09:55
    0
    • L Lasith
      25 Oct 2017, 09:46

      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 Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 25 Oct 2017, 09:55 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 25 Oct 2017, 09:58
      0
      • J J.Hilk
        25 Oct 2017, 09:55

        @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 25 Oct 2017, 09:58 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 1 Reply Last reply 25 Oct 2017, 10:00
        0
        • L Lasith
          25 Oct 2017, 09:58

          @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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 25 Oct 2017, 10:00 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 25 Oct 2017, 10:05
          1
          • J J.Hilk
            25 Oct 2017, 10:00

            @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 25 Oct 2017, 10:05 last edited by
            #5

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

            1 Reply Last reply
            0

            5/5

            25 Oct 2017, 10:05

            • Login

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