from main gui starting classes with request
for(int i=0; i< list.count(); i++)
{
((Class1*)list.at(i))->startProcess();
}
for(int i=0; i< list.count(); i++)
{
((Class1*)list.at(i))->startProcess();
}
To copy to clipboard, switch view to plain text mode
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);
//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);
}
}
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);
}
}
To copy to clipboard, switch view to plain text mode
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();
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
somewhere about response
void Class1::replyFinished_listDesc(QNetworkReply* reply)
{
if(abort)
{
return;
}
.......
}
void Class1::replyFinished_listDesc(QNetworkReply* reply)
{
if(abort)
{
return;
}
.......
}
To copy to clipboard, switch view to plain text mode
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;
}
for(int i=0; i< list.count(); i++)
{
Class1* t = (Class1*)list.at(i);
t->stop();
delete t;
}
To copy to clipboard, switch view to plain text mode
where is problem? which right way to delete QNetworkReply's and QNetworkAccessManagers?
Bookmarks