Answer the question
In order to leave comments, you need to log in
Qt. Working with Habrahabr API?
Task
For fun, I decided to write a Qt program for mobile phones. The program allows you to view karma, rating, position in the user's rating. This will be my first project that needs to work with the web .
Problem
I don't know how the connection and download of the file are implemented. At first I tried to write like this:
QFile xml_input("http://habrahabr.ru/api/profile/user");
bool flag = xml_input.open(QFile::ReadOnly);
Answer the question
In order to leave comments, you need to log in
QNetworkAccessManager is very good, but in QHTTP everything will be much simpler, reading into a string is easy, writing to a file is even easier.
If you are going to write in Qt, you absolutely need to understand what signals and slots are. If you have figured out how to use signals and slots, then ask specific questions about QNetworkAccessManager. If not, figure it out, without them you won’t go far with Qt.
The easiest option is to request via QNetworkAccessManager. The documentation about it has a lot of information and examples doc.qt.nokia.com/latest/qnetworkaccessmanager.html
The bottom line is that you need to make a GET request to the API page. The result will be returned as a pointer to the QNetworkReply in the slot parameter and can be extracted to a string by the QNetworkReply::readAll() method.
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://habrahabr.ru/api/profile/tucnak")));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question