View Full Version : file copy in Qt 3.3.4 ?

1st March 2006, 12:26
Hi all,

I am trying to copy directory and it files.

For that I need to use QFile::copy ..

But I'm not able to get copy method in Qt 3.3.4 QFile class.

Where can I find the copy method ... Is there any other option to do that ??

thanks for any ideas.

1st March 2006, 12:44
See wysotas answer.

You will have to implement it your self.
Along the lines of:
- open source file
- open target file
- read source file
- write read content in to target file
- close both files.

It could look something like:

QFile source("file1");
QFile dest("file2");
//open the files with the right IO flags
QDataStream readStream(&source);
QDataStream writeStream(&dest);

//close files

1st March 2006, 12:44

30th March 2006, 03:55

I have not been able to get this to work. Here is my code:

QUrlOperator urlOp;


qDebug(dirs.ref_dir + (QString) "/");

// copy the reference file to ~/.lprof/target_refs
urlOp.copy( TargetSelector->getFilename(), dirs.ref_dir + (QString) "/");

The two qDebug lines are to confirm that the from file name and the to directory name are both correct (they are). I tried with and without the trailing "/" on the to directory. What do I need to do to make this work?

30th March 2006, 10:25
Try without using "~".

30th March 2006, 19:52
I am not using "~". The files are being copied into a user configuration directory. So the reference to ~/.lprof/target_refs in the comment is short hand for the file is being copied to the user's home directory. The code is using the fully qualified path to the location where the file should be copied. It is also using a fully qualified from file name.

This code is a rewrite of code that built a cp or copy command string (depending on OS) and then called system to copy the file. The code using system call has been in production for some months now. I used qDebug to dump out the from and to file/directory to the console and these are correct. I should have removed the comment as it was aparently confusing.

31st March 2006, 15:43
QUrlOperator in an asynchronous class. It means that when you issue copy(), the application is not blocked until the copy is finished, but it goes on. You created your operator on stack. When you exit the function all stack objects (including your QUrlOperator) are destroyed. QUrlOperator just doesn't have enough time to carry out the operation. Try creating it on heap instead (QUrlOperator *op = new QUrlOperator(...)).