Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved]QNetwork and QLabel
Qt 6.11 is out! See what's new in the release blog

[solved]QNetwork and QLabel

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bio120
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      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.

      http://anavi.org/

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        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()))@

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bio120
          wrote on last edited by
          #4

          Thanks. I will try it

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dotK
            wrote on last edited by
            #5

            I had the same problem, worked with me.

            [.k] - A Mad Programmer

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bio120
              wrote on last edited by
              #6

              [quote author="dotK" date="1359023688"]I had the same problem, worked with me.[/quote]

              The 1st reply helped me. Maybe it helps you too

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved