I'm new to Qt. I installed Qt for VS2008 and integrated with my VS2010. I just want to know how to make HTTP requests. I've read about QtNetwork but QtHttp is obselete.
I also know about libcurl and curlpp, but I have problems installing it, and making it work with Qt.
What do you recommend, QtNetwork or curlpp? If QtNetwork, can you please give me a sample function or piece of code (and what class to use). If curlpp(libcurl), can you please point me to somewhere where I can find the steps to install it for Qt (or kindly explain)?
Thank you very much.
libcurl and curlpp are great libraries, but using them adds a dependency to your project that probably you can avoid.
Recent versions of Qt recommend to use QNetworkAccessManager
to make network requests (included http requests) and receive replies.
The simplest possible way to download a file is:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://stackoverflow.com")));
When the replyFinished
slot is called, the QNetworkReply
object that it takes as parameter will contain the downloaded data as well as meta-data (headers, etc.).
A more complete example can be found in the Qt examples, you can read here its source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With