QHttp and QFile not closing
I have the following function
Code:
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();
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);
downloadsTW->setItem(workingRow, 7, requestIdItem);
}
httpObjects.remove(sendHttp);
sendHttp->deleteLater();
if((httpObjects.count() < numDownloads) && (!downloadQueue.isEmpty()))
{
startDownload();
}
}
that is connected like so:
Code:
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
Re: QHttp and QFile not closing
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
Re: QHttp and QFile not closing
Quote:
Originally Posted by
marcel
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