PDA

View Full Version : QUrlOperator bug or what?



thelinuxer
2nd August 2007, 13:12
Hi Everyone,
I have been trying to use QUrlOperator to copy some files from one loaction to another. The strange thing is that I keep on receiving dataTransferProgress signal and the progress bar advances but no file is created and everything goes normal untill I get a finished signal but nothing is copied. After waiting for some more time I found out that I keep on receiving dataTransferProgress signal and then a finished signal and this time the file is copied! This second time gets started without any interaction from me.

I am using Qt 3.3.7 under Linux Kubuntu feisty.

Here is my code:



void MyClass::CopyMarked(bool move)
{
// m_currDir = "/tmp";
if (m_markedList.isEmpty())
return;

QString msg = (move) ?
tr("Moving marked files...") : tr("Copying marked files...");

//.....
// Here a seelctor dialog appears to choose the destination
//......
if(selector.exec() == QDialog::Accepted){
QUrlOperator* copyOperator = new QUrlOperator;

int size = 0;
QString msg;
//m_markedList contains the names of the files to be copied or moved
for (unsigned int i = 0; i < m_markedList.count() ; i++)
{
QFile file(*m_markedList.at(i));
size += file.size();
}

m_copyProgress = new MythProgressDialog(msg, size);

connect(copyOperator,SIGNAL(dataTransferProgress(i nt,int,QNetworkOperation*)),
this,SLOT(dataTransferProgress(int,int,QNetworkOpe ration*)));

connect(copyOperator,SIGNAL(finished(QNetworkOpera tion*)),
this,SLOT(finished(QNetworkOperation*)));

copyOperator->copy(m_markedList,selector.getSelected(),move);
}
}

void MyClass::dataTransferProgress(int bytesDone, int, QNetworkOperation*)
{
m_copyProgress->setProgress(bytesDone);
}

void MyClass::finished(QNetworkOperation*)
{
m_copyProgress->close();
}


Thanx in advance,
Ahmed Toulan.

marcel
2nd August 2007, 13:28
dataTransferProgress will be particular for every file in the list you pass to copy.
Also, you have to examine the QNetworkOperation pointer that is passed to you with each finished signal. BTW, you also get a finished signal after each single file copy operation is done.


So:
1. Your progress handling is wrong.
2. Look at the type of QNetworkOperation in finished, to see what exactly has finished.
For copy I think QNetworkProtocol::OpGet is what you should have.

Regards

thelinuxer
2nd August 2007, 13:34
dataTransferProgress will be particular for every file in the list you pass to copy.
Also, you have to examine the QNetworkOperation pointer that is passed to you with each finished signal. BTW, you also get a finished signal after each single file copy operation is done.


So:
1. Your progress handling is wrong.
2. Look at the type of QNetworkOperation in finished, to see what exactly has finished.
For copy I think QNetworkProtocol::OpGet is what you should have.

Regards

Thanx for replying.

It seems that my progress handling is wrong, but the behavior I am describing happens when I am trying to copy a single file.

Also, how can we know that we finished copying all file?

Regards,
Ahmed Toulan.

marcel
2nd August 2007, 13:39
Thanx for replying.
It seems that my progress handling is wrong, but the behavior I am describing happens when I am trying to copy a single file.

Weird.

[/quote]
Also, how can we know that we finished copying all file?
[/quote]

You always have the startedNextCopy signal that you can connect to.
Another solution is to use the other version of copy, for a single file, in conjunction with the finished signal.
When you get the finished signal for a copy operation, then you know that it is ok to start the next one.
For this you will have to queue your files.

Regards