PDA

View Full Version : QNetworkAccessManager crash with deleting parent pointer



majatu
14th October 2011, 14:03
from main gui starting classes with request


for(int i=0; i< list.count(); i++)
{
((Class1*)list.at(i))->startProcess();
}

staring get requests


for (int i=0; i< this->list.count(); i++)
{
if(!abort)
{
MyNetworkAccessManager *manager = new MyNetworkAccessManager(this);
manager->i = i;
manager->moveToThread(this->thread());
manager->setParent(this);

QString url = list.at(i)->url;

//qDebug()<< "get " + url;

QNetworkReply* reply = manager->get(QNetworkRequest(QUrl(url)));
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished_listDesc(QNetworkReply*)));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress_listDesc(qint64,qint64)));
connect(reply, SIGNAL(finished()), this, SLOT(finished_listDesc()));
connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead_listDesc()));
this->listReplies.append(reply);
}
}

trying to delete obejcts


void Class1::stop()
{
abort = true;

for(int i=0; i < listReplies.count(); i++)
{
QNetworkReply *reply = (QNetworkReply *)listReplies.at(i);
reply->disconnect();
reply->manager()->disconnect();
reply->abort();
reply->deleteLater();
reply->manager()->deleteLater();
}
}

somewhere about response


void Class1::replyFinished_listDesc(QNetworkReply* reply)
{
if(abort)
{
return;
}

.......

}


deleting pointers of classes, crashes on delete t; string


for(int i=0; i< list.count(); i++)
{
Class1* t = (Class1*)list.at(i);
t->stop();
delete t;
}

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

llev
16th October 2011, 09:39
Did you try t->deleteLater() instead of delete t?

amleto
16th October 2011, 23:25
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


for(int i=0; i< list.count(); i++)
{
Class1* t = (Class1*)list.at(i);
t->stop();
delete t;
}

? 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?