PDA

View Full Version : QFile::copy says “can't open source file for input”?



.:saeed:.
17th July 2013, 21:13
I'm going to copy one file using QFile::copy function but this function always returns false and errorString says :

"Cannot open D:/tmp/buf34.txt for input"
I tried to run this program with administrator privilege but nothing changed. My code is really simple :


QString source = url.toLocalFile();
QString destination = _dir.absolutePath()
+ QString("/%1").arg(QFileInfo(source).fileName());
qDebug()<<"Cp from :" << source << " to : "<< destination;
QFile file(source);
qDebug()<<file.copy(destination);
qDebug()<<file.errorString();

I have QListView occupied with a QFileSystemModel. I try to drag one file from this ListView to a QLabel. For the QLabel a destination path is set. In drop event I try to copy file.

anda_skoa
20th July 2013, 19:16
Assuming the file exists and you have read permissions for it, check that it is not opened somewhere else in either your program or another.
Window's file system uses a allow-open-only-once restriction.

Cheers,
_