Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved QFile::copy creates an empty file

    General and Desktop
    qfile copy files qt5.5.1 linux
    3
    4
    2109
    Loading More Posts
    • 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
      Danysan last edited by Danysan

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • D
          Danysan last edited by Danysan

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

          1 Reply Last reply Reply Quote 0
          • J
            j.sunderland last edited by

            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 Reply Quote 0
            • First post
              Last post