PDA

View Full Version : QHttp and QFile not closing



maxpower
1st May 2007, 17:20
I have the following function


void SSDownloaderMWI::httpDone(bool error)
{
QHttp *sendHttp = static_cast<QHttp*>(sender());
int currentID = httpObjects[sendHttp];
QFile *file = (QFile*)sendHttp->currentDestinationDevice();
QList<QTableWidgetItem*> items = downloadsTW->findItems(QString::number(currentID), Qt::MatchFixedString);
if(items.count() != 0)
{
int workingRow = items.at(0)->row();
QTableWidgetItem *finishedStatus = new QTableWidgetItem("Done");
if(file) {
file->close();
file->deleteLater();
}
if(error)
{
finishedStatus->setText("Done Error");
}

QString host = downloadsTW->item(workingRow, 10)->text();

if(activeHostsList.contains(host))
{
int index = activeHostsList.indexOf(host) + 1;
int num = activeHostsList.at(index).toInt();
num--;
activeHostsList.replace(index, QString::number(num));
}

downloadsTW->setItem(workingRow, 4, finishedStatus);
QTableWidgetItem *requestIdItem = new QTableWidgetItem("");
downloadsTW->setItem(workingRow, 7, requestIdItem);
}




httpObjects.remove(sendHttp);
sendHttp->deleteLater();

if((httpObjects.count() < numDownloads) && (!downloadQueue.isEmpty()))
{
startDownload();
}
}


that is connected like so:


connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));


when a new url is added to my download manager. The status in my table is updated as it should be but the file is not valid and therefore the file is not closed/released until my application exits. How else can I get a valid pointer to the destination file so my application releases the file?

PS I am running Ubuntu 7.04 with Qt 4.2.3 and I can verify the file is open using lsof.

Thanks
mAx

marcel
1st May 2007, 17:29
Why don't you delete the file right there, after you close it?
There is clearly stated in Assistant:
This function can be used to delete the QIODevice (http://www.qtcentre.org/forum/qiodevice.html) in the slot connected to the requestFinished (http://www.qtcentre.org/forum/qhttp.html#requestFinished)() signal.

Could you look at what QIODevice::openMode() returns after you close it? Also, try deleting the file right there, and check if it closes...

Regards

maxpower
1st May 2007, 17:38
Why don't you delete the file right there, after you close it?
There is clearly stated in Assistant:

Could you look at what QIODevice::openMode() returns after you close it? Also, try deleting the file right there, and check if it closes...

Regards

I moved my code to requestFinished and it does work. I am having a hard time remembering why but I did stop using requestFinished for some reason (I believe one of the sites I download from regularly does not behave correctly). Anyway I will leave it like this until I have a problem.

Thanks
mAx