QNetworkReply
is a sequential-access QIODevice
in which whenever more data is received from the network, the readyRead()
signal is emitted. So your readyRead()
slot will probably get called multiple times as new data comes gradually. So you should not initialize your file in that slot. The file initialization should be done in onDownServ()
slot once:
QNetworkAccessManager *nam = new QNetworkAccessManager();
QUrl url2("ftp://test.cz/plugins.txt");
url2.setPassword("test");
url2.setUserName("test");
save=new QFile("plugins.txt");
if (!save->open(QIODevice::WriteOnly))
return;
reply = nam->get(QNetworkRequest(url2));
When you do file initialization in readyRead()
slot, it opens file in the first call and subsequent calls are returned as it can not open the new file for write operation. So the readyRead()
slot gets called repeatedly and the application crashes.