Results 1 to 3 of 3

Thread: QHttp and QFile not closing

  1. #1
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QHttp and QFile not closing

    I have the following function
    Qt Code:
    1. void SSDownloaderMWI::httpDone(bool error)
    2. {
    3. QHttp *sendHttp = static_cast<QHttp*>(sender());
    4. int currentID = httpObjects[sendHttp];
    5. QFile *file = (QFile*)sendHttp->currentDestinationDevice();
    6. QList<QTableWidgetItem*> items = downloadsTW->findItems(QString::number(currentID), Qt::MatchFixedString);
    7. if(items.count() != 0)
    8. {
    9. int workingRow = items.at(0)->row();
    10. QTableWidgetItem *finishedStatus = new QTableWidgetItem("Done");
    11. if(file) {
    12. file->close();
    13. file->deleteLater();
    14. }
    15. if(error)
    16. {
    17. finishedStatus->setText("Done Error");
    18. }
    19.  
    20. QString host = downloadsTW->item(workingRow, 10)->text();
    21.  
    22. if(activeHostsList.contains(host))
    23. {
    24. int index = activeHostsList.indexOf(host) + 1;
    25. int num = activeHostsList.at(index).toInt();
    26. num--;
    27. activeHostsList.replace(index, QString::number(num));
    28. }
    29.  
    30. downloadsTW->setItem(workingRow, 4, finishedStatus);
    31. QTableWidgetItem *requestIdItem = new QTableWidgetItem("");
    32. downloadsTW->setItem(workingRow, 7, requestIdItem);
    33. }
    34.  
    35.  
    36.  
    37.  
    38. httpObjects.remove(sendHttp);
    39. sendHttp->deleteLater();
    40.  
    41. if((httpObjects.count() < numDownloads) && (!downloadQueue.isEmpty()))
    42. {
    43. startDownload();
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

    that is connected like so:
    Qt Code:
    1. 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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    This function can be used to delete the QIODevice in the slot connected to the requestFinished() signal.
    Could you look at what QIODevice:penMode() returns after you close it? Also, try deleting the file right there, and check if it closes...

    Regards

  3. The following user says thank you to marcel for this useful post:

    maxpower (1st May 2007)

  4. #3
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QHttp and QFile not closing

    Quote Originally Posted by marcel View Post
    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:penMode() 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

Similar Threads

  1. need help for QHttp
    By patcito in forum Qt Programming
    Replies: 9
    Last Post: 1st June 2006, 07:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.