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();
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();
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
that is connected like so:
connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
To copy to clipboard, switch view to plain text mode
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
Bookmarks