PDA

View Full Version : QNetworkAccessManager used by QTimer causes falling



gibucsoft
1st December 2016, 18:55
I am using QNetworkAccessManager in function, which is run periodically by QTimer. The code is:


QTimer* timer=new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(findUpdate()));
timer->setSingleShot(false);
timer->start(frequency*1800000);

void MainWindow::findUpdate()
{
for (int i=0;i<aplikace.count();i++){
QNetworkAccessManager* manager=new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),t his,SLOT(checkUpdate(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://www.gibucsoft.8u.cz/"+lang+"gibuclauncher/verze.php?ver="+aplikace.at(i))));
}
}

The compilation is fine and when I run my application from the Qt Creator it is OK as well but when I run it from the OS the program falls after a while (but not long enough for the timer to even start the function findUpdate). Sometimes before falling this error message shows:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

gibucsoft
2nd December 2016, 17:18
I already know the solution, the error was in creating a new QNetworkAccessManager each time. When I use only one, the application seems to work fine. But strange is, that in previous versions of my application it worked with multiple instances as well.

anda_skoa
3rd December 2016, 13:09
Even a new QNetworkAccessManager should work, just very wasteful.

In any case the primary way to debug a crash is to look at the stack trace at the time of crash.

Cheers,
_