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::copy creates an empty file
QtWS25 Last Chance

QFile::copy creates an empty file

Scheduled Pinned Locked Moved Unsolved General and Desktop
qfilecopyfilesqt5.5.1linux
4 Posts 3 Posters 2.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.
  • D Offline
    D Offline
    Danysan
    wrote on 24 Jan 2016, 10:18 last edited by Danysan
    #1

    Hi,
    I am developing in QTCreator, with QT5.5.1 under Linux, a service which needs to copy a file (its path is in the QString clocksDataPath and the destination path is in the QString destination). I created this code:

    if(QFile(destination).exists() && ! QFile::remove(destination))
        qCritical() << "Failed removing " << destination;
    
    if( ! QFile::copy(clocksDataPath,destination))
        qCritical() << "Failed copying " << clocksDataPath;
    

    None of these declaration returns an error, though when I go and analyze the file, it's completely empty.
    Both paths require root permissions but the application runs as system service, so that shouldn't be a problem.
    What am I forgetting?

    If it can help, the full code is here: https://github.com/Danysan1/radeon-profile-daemon/blob/Development/radeon-profile-daemon/rpdthread.cpp#L116

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jan 2016, 23:08 last edited by
      #2

      Hi and welcome to devnet,

      Maybe a silly question but are you sure that the original file contains something ? Since it's the sysfs file system, you may have to open and read the file to get something from it.

      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
      0
      • D Offline
        D Offline
        Danysan
        wrote on 25 Jan 2016, 11:50 last edited by Danysan
        #3

        Yes, I checked that it is not empty before running it. I will try opening and reading it

        1 Reply Last reply
        0
        • J Offline
          J Offline
          j.sunderland
          wrote on 10 May 2017, 16:01 last edited by
          #4

          I was having this same problem, turns out I was restarting too soon. The file transfer was so slow that took over a minute to transfer a 2Mb file.

          I still don't have a good solution, I am using system("cp file1 file2") for Linux as a workaround, but don't have any suggestions for a portable solution.

          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