Unsolved QFile::copy creates an empty file
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
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.
Yes, I checked that it is not empty before running it. I will try opening and reading it
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.