T
T
tucnak2011-07-28 21:28:06
Qt
tucnak, 2011-07-28 21:28:06

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);

flag - returns zero. I found a couple of articles that describe a method using QNetworkAccessManager . But there I did not understand anything. If you can explain. Is there an easier method?
Desire
It is necessary that at the output I get a clean QFile with XML stuffing. But the line is fine too...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TheHorse, 2011-07-28
@tucnak

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.

P
Paul, 2011-07-29
@Paul

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.

K
kharvd, 2011-07-28
@kharvd

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 question

Ask a Question

731 491 924 answers to any question