In my project, I need to download a 1.5MB file from a server. I was able to achieve this in my GUI application like this:
QNetworkAccessManager* m_NetworkMngr = new QNetworkAccessManager(this);
QNetworkReply *reply = m_NetworkMngr->get(QNetworkRequest(QUrl("someurl.com")));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QUrl aUrl("someurl.com");
QFileInfo fileInfo=aUrl.path();
QFile file(aPathInClient+"\\"+fileInfo.fileName());//aPathInClient is predefined
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
delete reply;
I am getting the following error:
'connect' function does not take four arguments.
How can I modify the signals and slots to work in my console application?
My guess is that your code is correct with regards to establishing signal/slot connection, however compiler seems to be confused because of the connect()
function name and cannot resolve it properly: whether it is QObject::connect()
that takes at least 4 arguments, or it is another function with the same name, but different signature. I would suggest to try to explicitly tell compiler which function to use, i.e.:
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));