How to copy a file from one directory to another with Qt3.3.3. ?
Hi,
I'm looking for a function to copy a file from a directory to another ... but this function is not located in that class.
Where could I find this function ?
Then I search a little bit and I discover a class nammed QUrlOperator, is that class could do what I want on a windows file system ? If yes how does it works ?
I code the two following slots
Code:
void testDialog::init()
{
QUrlOperator op("c:\\user\\AFile.txt");
QUrlInfo fi
= op.
info("c:\\user\\AFile.txt");
message = "Filename = " + fi.name();
write(message);
}
void testDialog
::write( const QString &line
) {
lb->insertItem(line);
lb->setBottomItem(lb->count()-1);
}
... but it does not write the file name, what's wrong with my code ?
Thanks in advance.
Re: How to copy a file from one directory to another with Qt3.3.3. ?
I made some changes to my code
Code:
QUrlOperator *op = new QUrlOperator();
QString target
= "c:/user/AFileCopied.txt";
op->copy(src, target, false, false);
write(fi.name());
The file is well copied but my url info object does not give me any info, why ?
Re: How to copy a file from one directory to another with Qt3.3.3. ?
Probably because QUrlOperator::copy is an asynchronous operation, so in the time of creating that QUrlInfo object the destination might not exist yet.
Re: How to copy a file from one directory to another with Qt3.3.3. ?
Ok ,so I must connect the finished signals to one of my slot to be sure that the operation is over.
Code:
void testDialog::init()
{
targetPath
= QDir::currentDirPath();
targetFile = targetPath+"/AFile.txt";
op = new QUrlOperator(targetPath);
connect(op, SIGNAL(finished(QNetworkOperation*)), SLOT(displayInfo(QNetworkOperation* _nop)));
nop = op->listChildren();
}
void testDialog
::write( const QString &line
) {
lb->insertItem(line);
lb->setBottomItem(lb->count()-1);
}
void testDialog::displayInfo( QNetworkOperation * _nop )
{
write(fi.name());
}
but my slot is never called, what's wrong again ?
Re: How to copy a file from one directory to another with Qt3.3.3. ?
I don't see the code for starting the operation itself. Did you have a look at the example from Qt docs?