PDA

View Full Version : Problem with QFile and copying;



Nefastious
31st October 2009, 16:12
Hi there guys,

I have a bit of a problem here, I have the following code:


QFile file;
QString newpath;
newpath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/", QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);

file.copy ( "/Applications/medadmin/sampledatabase", newpath);

The problem is: it doesn't copy the file to the place the user has selected it to.

What am I doing wrong? Any suggestions would be greatly appreciated;


Thanks in advance,

Nefastious

squidge
31st October 2009, 16:32
The 'copy' method you are using is static, so doesn't require an object. Therefore QFile::copy is fine, rather than file.copy. I doesn't make any difference but I like to emphasize that fact in the code, and if your only using static methods from a class, why waste the memory allocating the object?

Secondly, what does 'copy' return? You should always check return values of functions that return such values. If it's false then the function failed, most likely because the destination file already exists, couldn't be opened, or the path is invalid.

The documentation mentions nothing about copying to just a path (ie. no filename included), so I would assume this means it doesn't handle it.