[solved]QNetwork and QLabel
-
Hi all, I'm sorry if my topic in the wrong forum.
I have a problem. I try to get text (answer) from remote server and write it to QLabel but my code doesn't works. Here is it:
@static QNetworkAccessManager am;
QUrl url("https://api.vk.com/method/audio.get");
url.addQueryItem("access_token","some_code");
QNetworkRequest request(url);
QNetworkReply* reply = am.get(request);
label1->setText(reply->read());@Please, help me to solve my problem, if you can
-
Check the example at Qt Project wiki for "downloading data from URL":http://qt-project.org/wiki/Download_Data_from_URL The example usage shows how to download an image an to set it on a QPushButton. You can easily modify it to download text and to set it to a QLabel.
-
You tried to read "reply" even though the request isn't finished yet.
create a slot first:
@//.h
public slots: //you can use private slots
void download();
@@//.cpp
void className::download() //className is whatever you are using
{
label1->setText(reply->read());
}@then use signal-slot mechanism:
@static QNetworkAccessManager am;
QUrl url("https://api.vk.com/method/audio.get");
url.addQueryItem("access_token","some_code");
QNetworkRequest request(url);
QNetworkReply* reply = am.get(request);
QObject::connect(reply,SIGNAL(finished()),this,SLOT(download()))@