Results 1 to 3 of 3

Thread: QNetworkAccessManager crash with deleting parent pointer

  1. #1
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    1

    Default QNetworkAccessManager crash with deleting parent pointer

    from main gui starting classes with request

    Qt Code:
    1. for(int i=0; i< list.count(); i++)
    2. {
    3. ((Class1*)list.at(i))->startProcess();
    4. }
    To copy to clipboard, switch view to plain text mode 

    staring get requests

    Qt Code:
    1. for (int i=0; i< this->list.count(); i++)
    2. {
    3. if(!abort)
    4. {
    5. MyNetworkAccessManager *manager = new MyNetworkAccessManager(this);
    6. manager->i = i;
    7. manager->moveToThread(this->thread());
    8. manager->setParent(this);
    9.  
    10. QString url = list.at(i)->url;
    11.  
    12. //qDebug()<< "get " + url;
    13.  
    14. QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(url)));
    15. connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished_listDesc(QNetworkReply*)));
    16. connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress_listDesc(qint64,qint64)));
    17. connect(reply, SIGNAL(finished()), this, SLOT(finished_listDesc()));
    18. connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead_listDesc()));
    19. this->listReplies.append(reply);
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    trying to delete obejcts

    Qt Code:
    1. void Class1::stop()
    2. {
    3. abort = true;
    4.  
    5. for(int i=0; i < listReplies.count(); i++)
    6. {
    7. QNetworkReply *reply = (QNetworkReply *)listReplies.at(i);
    8. reply->disconnect();
    9. reply->manager()->disconnect();
    10. reply->abort();
    11. reply->deleteLater();
    12. reply->manager()->deleteLater();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    somewhere about response

    Qt Code:
    1. void Class1::replyFinished_listDesc(QNetworkReply* reply)
    2. {
    3. if(abort)
    4. {
    5. return;
    6. }
    7.  
    8. .......
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 


    deleting pointers of classes, crashes on delete t; string

    Qt Code:
    1. for(int i=0; i< list.count(); i++)
    2. {
    3. Class1* t = (Class1*)list.at(i);
    4. t->stop();
    5. delete t;
    6. }
    To copy to clipboard, switch view to plain text mode 

    where is problem? which right way to delete QNetworkReply's and QNetworkAccessManagers?

  2. #2
    Join Date
    Aug 2011
    Posts
    44
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: QNetworkAccessManager crash with deleting parent pointer

    Did you try t->deleteLater() instead of delete t?

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QNetworkAccessManager crash with deleting parent pointer

    only posting limited code is really annoying - hiding context doesnt help!

    how are Class1 'new'd ? do they have parents? If they have a parent, you should not 'delete' it.

    where is this
    Qt Code:
    1. for(int i=0; i< list.count(); i++)
    2. {
    3. Class1* t = (Class1*)list.at(i);
    4. t->stop();
    5. delete t;
    6. }
    To copy to clipboard, switch view to plain text mode 
    ? what class? what function?

    Why does class1 control the others' scope when it seems like it should be the most independant class?

    Have you used the dubugger? I'm sure it gave you more information than 'crash'. Why didnt you include that here?
    Last edited by amleto; 17th October 2011 at 00:32.

Similar Threads

  1. Correctly deleting a qwidget with no parent
    By boblatino in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2010, 07:01
  2. deleting invalid pointer
    By hollowhead in forum General Programming
    Replies: 11
    Last Post: 30th April 2010, 11:47
  3. Deleting Class causes app crash
    By been_1990 in forum Qt Programming
    Replies: 8
    Last Post: 29th January 2010, 18:52
  4. deleting internal pointer in QModelIndex
    By rickbsgu in forum Qt Programming
    Replies: 18
    Last Post: 24th December 2008, 03:24
  5. Replies: 1
    Last Post: 28th July 2006, 15:10

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.