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. qfile link function not working

qfile link function not working

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.6k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

    What does that qDebug() print ?

    Also why call QApplication::clipboard()->text() so many times ? You already have your QFileInfo object that contains the information you need.

    On a side note, if the target already exists, link will return false (or at list it's what the link member function will do).

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

    S 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      What does that qDebug() print ?

      Also why call QApplication::clipboard()->text() so many times ? You already have your QFileInfo object that contains the information you need.

      On a side note, if the target already exists, link will return false (or at list it's what the link member function will do).

      S Offline
      S Offline
      saber
      wrote on last edited by
      #5

      @SGaist
      same as what i put in

      "file:///home/shaber/Downloads/gh/NH.png" "/home/shaber/Downloads/NH.png"
      

      i cam up with this ,but no change , always broken file.

          QString o(QApplication::clipboard()->text());
          QString newPath;
          if (!curIndex.isDir()) newPath = curIndex.filePath();
          else newPath = ui->pathEdit->text();
      
          QFileInfo f(o);
          QString a(f.fileName());
          QString sf(newPath+ "/" + a);
      
          qDebug() << o << sf ;
      
          QFile::link(o,sf);
      
      JonBJ 1 Reply Last reply
      0
      • S saber

        @SGaist
        same as what i put in

        "file:///home/shaber/Downloads/gh/NH.png" "/home/shaber/Downloads/NH.png"
        

        i cam up with this ,but no change , always broken file.

            QString o(QApplication::clipboard()->text());
            QString newPath;
            if (!curIndex.isDir()) newPath = curIndex.filePath();
            else newPath = ui->pathEdit->text();
        
            QFileInfo f(o);
            QString a(f.fileName());
            QString sf(newPath+ "/" + a);
        
            qDebug() << o << sf ;
        
            QFile::link(o,sf);
        
        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #6

        @saber
        If your problem is really to do with the clipboard, putting in and showing us the output from a few judicious qDebug()s should help. Show the actual code and the actual output from qDebug() where you compare doing the same thing on identical paths with both literal strings in code and what you put on the clipboard.

        Meanwhile, also say what actually goes wrong. "Does not work" does not help us, and what does "using qfileinfo it creates a broken file." actually mean, what is a "broken file"? Don't you need to show us the output of ls -l on the symbolic link? Help us to help you....

        S 1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #7

          @saber said in qfile link function not working:

          "file:///home/shaber/Downloads/gh/NH.png" "/home/shaber/Downloads/NH.png"

          is not the same as:

          "/home/shaber/Downloads/gh/NH.png" "/home/shaber/Downloads/NH.png"

          file:/// makes it an URI. As I suggested before, use the path provided by QFileInfo.

          But before that, use QUrl::toLocalFile to get the proper path.

          In which case, and depending on what use you have of QFileInfo, you might not need it anymore.

          [edit: Fixed missing information SGaist]

          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
          1
          • JonBJ JonB

            @saber
            If your problem is really to do with the clipboard, putting in and showing us the output from a few judicious qDebug()s should help. Show the actual code and the actual output from qDebug() where you compare doing the same thing on identical paths with both literal strings in code and what you put on the clipboard.

            Meanwhile, also say what actually goes wrong. "Does not work" does not help us, and what does "using qfileinfo it creates a broken file." actually mean, what is a "broken file"? Don't you need to show us the output of ls -l on the symbolic link? Help us to help you....

            S Offline
            S Offline
            saber
            wrote on last edited by saber
            #8

            @JonB

            @SGaist itried with file info ,not working

                QString o(QApplication::clipboard()->text());
                QString newPath;
                if (!curIndex.isDir()) newPath = curIndex.filePath();
                else newPath = ui->pathEdit->text();
            
                QFileInfo f(o);
                QString a(f.fileName());
                QString sf(newPath+ "/" + a);
            
                qDebug() << f.filePath() << sf ;
            
                QFile::link(f.filePath(),sf);
            

            here is the terminal output

            drwxr-xr-x 32 shaber shaber 4096 Nov 29 13:50  apps
            lrwxrwxrwx  1 shaber shaber   57 Nov 29 16:36 'Copy (1) of ju.m4a' -> 'file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a'
            drwxr-xr-x  2 shaber shaber 4096 Nov 25 17:59  git
            drwxr-xr-x  4 shaber shaber 4096 Nov 29 13:38  manjaro
            drwxr-xr-x  4 shaber shaber 4096 Nov 25 15:24 'New Folder'
            -rw-r--r--  1 shaber shaber   53 Nov 27 11:32  task
            drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:23  test
            drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:34  testFolder
            -rwxr-xr-x  1 shaber shaber  136 Sep  9 12:10  Wallpaper.desktop
            
            

            here is debug output

            16:36:31: Starting /home/shaber/Desktop/apps/build-corefm-Desktop-Debug/corefm...
            qt5ct: using qt5ct plugin
            "file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a" "/home/shaber/Desktop/Copy (1) of ju.m4a"
            

            here is a woking link created by drictly putting the boyh paths. actufile name is NH.p[ng

            total 32
            drwxr-xr-x 32 shaber shaber 4096 Nov 29 13:50  apps
            lrwxrwxrwx  1 shaber shaber   57 Nov 29 16:36 'Copy (1) of ju.m4a' -> 'file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a'
            drwxr-xr-x  2 shaber shaber 4096 Nov 25 17:59  git
            drwxr-xr-x  4 shaber shaber 4096 Nov 29 13:38  manjaro
            drwxr-xr-x  4 shaber shaber 4096 Nov 25 15:24 'New Folder'
            lrwxrwxrwx  1 shaber shaber   32 Nov 29 16:41  NH.png -> /home/shaber/Downloads/gh/NH.png
            -rw-r--r--  1 shaber shaber   53 Nov 27 11:32  task
            drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:23  test
            drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:34  testFolder
            -rwxr-xr-x  1 shaber shaber  136 Sep  9 12:10  Wallpaper.desktop
            
            

            @JonB not working means, the file is not recognizeed as the typeit is originaly.system thinks it is a unknone file type

            JonBJ 1 Reply Last reply
            0
            • S saber

              @JonB

              @SGaist itried with file info ,not working

                  QString o(QApplication::clipboard()->text());
                  QString newPath;
                  if (!curIndex.isDir()) newPath = curIndex.filePath();
                  else newPath = ui->pathEdit->text();
              
                  QFileInfo f(o);
                  QString a(f.fileName());
                  QString sf(newPath+ "/" + a);
              
                  qDebug() << f.filePath() << sf ;
              
                  QFile::link(f.filePath(),sf);
              

              here is the terminal output

              drwxr-xr-x 32 shaber shaber 4096 Nov 29 13:50  apps
              lrwxrwxrwx  1 shaber shaber   57 Nov 29 16:36 'Copy (1) of ju.m4a' -> 'file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a'
              drwxr-xr-x  2 shaber shaber 4096 Nov 25 17:59  git
              drwxr-xr-x  4 shaber shaber 4096 Nov 29 13:38  manjaro
              drwxr-xr-x  4 shaber shaber 4096 Nov 25 15:24 'New Folder'
              -rw-r--r--  1 shaber shaber   53 Nov 27 11:32  task
              drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:23  test
              drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:34  testFolder
              -rwxr-xr-x  1 shaber shaber  136 Sep  9 12:10  Wallpaper.desktop
              
              

              here is debug output

              16:36:31: Starting /home/shaber/Desktop/apps/build-corefm-Desktop-Debug/corefm...
              qt5ct: using qt5ct plugin
              "file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a" "/home/shaber/Desktop/Copy (1) of ju.m4a"
              

              here is a woking link created by drictly putting the boyh paths. actufile name is NH.p[ng

              total 32
              drwxr-xr-x 32 shaber shaber 4096 Nov 29 13:50  apps
              lrwxrwxrwx  1 shaber shaber   57 Nov 29 16:36 'Copy (1) of ju.m4a' -> 'file:///home/shaber/Desktop/testFolder/Copy (1) of ju.m4a'
              drwxr-xr-x  2 shaber shaber 4096 Nov 25 17:59  git
              drwxr-xr-x  4 shaber shaber 4096 Nov 29 13:38  manjaro
              drwxr-xr-x  4 shaber shaber 4096 Nov 25 15:24 'New Folder'
              lrwxrwxrwx  1 shaber shaber   32 Nov 29 16:41  NH.png -> /home/shaber/Downloads/gh/NH.png
              -rw-r--r--  1 shaber shaber   53 Nov 27 11:32  task
              drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:23  test
              drwxr-xr-x  6 shaber shaber 4096 Nov 28 22:34  testFolder
              -rwxr-xr-x  1 shaber shaber  136 Sep  9 12:10  Wallpaper.desktop
              
              

              @JonB not working means, the file is not recognizeed as the typeit is originaly.system thinks it is a unknone file type

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #9

              @saber
              It's "not working" because what you have the link pointing to begins with file://. That means nothing to a Linux filing system. You need it pointing to /home/shaber/Desktop/testFolder/Copy (1) of ju.m4a (presumably). (I see @SGaist has already drawn your attention to this.)

              S 1 Reply Last reply
              0
              • JonBJ JonB

                @saber
                It's "not working" because what you have the link pointing to begins with file://. That means nothing to a Linux filing system. You need it pointing to /home/shaber/Desktop/testFolder/Copy (1) of ju.m4a (presumably). (I see @SGaist has already drawn your attention to this.)

                S Offline
                S Offline
                saber
                wrote on last edited by
                #10

                @JonB
                i notice that .but i can't find the way to get only the file path from qapplication::clipboard

                JonBJ 1 Reply Last reply
                0
                • S saber

                  @JonB
                  i notice that .but i can't find the way to get only the file path from qapplication::clipboard

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #11

                  @saber
                  @SGaist previously said:

                  file:/// makes it an URI. As I suggested before, use the path provided by QFileInfo.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by SGaist
                    #12

                    My answer was incomplete. Since you know it's an URI, use QUrl::toLocaleFile and you'll have the path you need.

                    I've updated my previous answer.

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

                    S 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      My answer was incomplete. Since you know it's an URI, use QUrl::toLocaleFile and you'll have the path you need.

                      I've updated my previous answer.

                      S Offline
                      S Offline
                      saber
                      wrote on last edited by
                      #13

                      @SGaist

                      it's working now.

                          QString o(QApplication::clipboard()->text());
                          QString newPath;
                          if (!curIndex.isDir()) newPath = curIndex.filePath();
                          else newPath = ui->pathEdit->text();
                      
                          QFileInfo f(o);
                          QString a(f.fileName());
                          QString sf(newPath+ "/" + a);
                      
                          qDebug() << f.filePath() << sf ;
                          QUrl l(f.filePath());
                      
                          QFile::link(l.toLocalFile(),sf);
                      
                      
                      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