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. How to get data from URL/.php file and display in my fields
Forum Updated to NodeBB v4.3 + New Features

How to get data from URL/.php file and display in my fields

Scheduled Pinned Locked Moved Solved Mobile and Embedded
30 Posts 2 Posters 6.5k 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.
  • V Offline
    V Offline
    Vineela
    wrote on 11 Jan 2019, 04:45 last edited by
    #1

    When I click a button I need to fetch data from URL(or .php file for exact ) and retrieve as a JSON array and display to my lineEdit or to comboBox , I've done this in Android Studio but no idea in Qt, as a request from newbie.

    J 1 Reply Last reply 11 Jan 2019, 05:47
    0
    • V Vineela
      11 Jan 2019, 04:45

      When I click a button I need to fetch data from URL(or .php file for exact ) and retrieve as a JSON array and display to my lineEdit or to comboBox , I've done this in Android Studio but no idea in Qt, as a request from newbie.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 11 Jan 2019, 05:47 last edited by
      #2

      @Vineela You should start here: http://doc.qt.io/qt-5/qnetworkaccessmanager.html
      For JSON: http://doc.qt.io/qt-5/qjsondocument.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply 11 Jan 2019, 06:33
      3
      • J jsulm
        11 Jan 2019, 05:47

        @Vineela You should start here: http://doc.qt.io/qt-5/qnetworkaccessmanager.html
        For JSON: http://doc.qt.io/qt-5/qjsondocument.html

        V Offline
        V Offline
        Vineela
        wrote on 11 Jan 2019, 06:33 last edited by
        #3

        @jsulm Thank you I'll try now

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vineela
          wrote on 14 Jan 2019, 04:51 last edited by Vineela
          #4

          Thanks @jsulm it worked I've gone through the first link but not tried with the json one but i got what i wanted.

          V 1 Reply Last reply 14 Jan 2019, 05:13
          1
          • V Vineela
            14 Jan 2019, 04:51

            Thanks @jsulm it worked I've gone through the first link but not tried with the json one but i got what i wanted.

            V Offline
            V Offline
            Vineela
            wrote on 14 Jan 2019, 05:13 last edited by Vineela
            #5

            @Vineela @jsulm i have one more request that how can I display 2 array strings from URL/.php and add to comboBox ??

            J 1 Reply Last reply 14 Jan 2019, 05:26
            0
            • V Vineela
              14 Jan 2019, 05:13

              @Vineela @jsulm i have one more request that how can I display 2 array strings from URL/.php and add to comboBox ??

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 14 Jan 2019, 05:26 last edited by
              #6

              @Vineela said in How to get data from URL/.php file and display in my fields:

              array strings

              What do you mean by this? Please explain better what you want to achieve.
              To display a string you can use QLabel.
              To add an entry to QComboBox use http://doc.qt.io/qt-5/qcombobox.html#addItem

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 1 Reply Last reply 14 Jan 2019, 07:41
              0
              • J jsulm
                14 Jan 2019, 05:26

                @Vineela said in How to get data from URL/.php file and display in my fields:

                array strings

                What do you mean by this? Please explain better what you want to achieve.
                To display a string you can use QLabel.
                To add an entry to QComboBox use http://doc.qt.io/qt-5/qcombobox.html#addItem

                V Offline
                V Offline
                Vineela
                wrote on 14 Jan 2019, 07:41 last edited by
                #7

                @jsulm From my .php link I'll get 2 or more arrays so how do i get them and add it to my combo box.

                J 1 Reply Last reply 14 Jan 2019, 07:42
                0
                • V Vineela
                  14 Jan 2019, 07:41

                  @jsulm From my .php link I'll get 2 or more arrays so how do i get them and add it to my combo box.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 14 Jan 2019, 07:42 last edited by
                  #8

                  @Vineela said in How to get data from URL/.php file and display in my fields:

                  2 or more arrays

                  Are you talking about Json?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  V 1 Reply Last reply 14 Jan 2019, 07:43
                  0
                  • J jsulm
                    14 Jan 2019, 07:42

                    @Vineela said in How to get data from URL/.php file and display in my fields:

                    2 or more arrays

                    Are you talking about Json?

                    V Offline
                    V Offline
                    Vineela
                    wrote on 14 Jan 2019, 07:43 last edited by
                    #9

                    @jsulm yep, I thought I may not use JSON, do I have to use JSON if yes then help me with JSON.

                    J 1 Reply Last reply 14 Jan 2019, 07:46
                    0
                    • V Vineela
                      14 Jan 2019, 07:43

                      @jsulm yep, I thought I may not use JSON, do I have to use JSON if yes then help me with JSON.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 14 Jan 2019, 07:46 last edited by
                      #10

                      @Vineela If the server sends Json then you have to deal with Json. I gave you a link to documentation for accessing Json data using Qt, you wrote you didn't read it. Now it is time to read that documentation.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • V Offline
                        V Offline
                        Vineela
                        wrote on 14 Jan 2019, 09:41 last edited by
                        #11

                        @jsulm this is the output of my link , well from this i need to get those "GNL0001 & GNL002" and add them to my combo box ,so i hope you get what I'm saying please help me out with this.
                        [
                        {
                        "LeaderCode": "GNL0001"
                        },
                        {
                        "LeaderCode": "GNL0002"
                        }
                        ]

                        J 1 Reply Last reply 14 Jan 2019, 11:48
                        0
                        • V Vineela
                          14 Jan 2019, 09:41

                          @jsulm this is the output of my link , well from this i need to get those "GNL0001 & GNL002" and add them to my combo box ,so i hope you get what I'm saying please help me out with this.
                          [
                          {
                          "LeaderCode": "GNL0001"
                          },
                          {
                          "LeaderCode": "GNL0002"
                          }
                          ]

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 14 Jan 2019, 11:48 last edited by jsulm
                          #12

                          @Vineela Did you read the documentation?

                          AByteArray data = "YOUR JSON DATA";
                          QJsonDocument doc = QJsonDocument::fromJson(data);
                          QJsonArray array = doc.array();
                          QJsonObject object = array.at(0).toObject();
                          QString code = object["LeaderCode"].toString();
                          

                          To add to QComboBox please refer to the documentation: http://doc.qt.io/qt-5/qcombobox.html#insertItem

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          V 1 Reply Last reply 14 Jan 2019, 12:12
                          2
                          • J jsulm
                            14 Jan 2019, 11:48

                            @Vineela Did you read the documentation?

                            AByteArray data = "YOUR JSON DATA";
                            QJsonDocument doc = QJsonDocument::fromJson(data);
                            QJsonArray array = doc.array();
                            QJsonObject object = array.at(0).toObject();
                            QString code = object["LeaderCode"].toString();
                            

                            To add to QComboBox please refer to the documentation: http://doc.qt.io/qt-5/qcombobox.html#insertItem

                            V Offline
                            V Offline
                            Vineela
                            wrote on 14 Jan 2019, 12:12 last edited by
                            #13

                            @jsulm well yes i've done and read the documentation but small thing is item which i added is blank.

                            J 1 Reply Last reply 14 Jan 2019, 12:16
                            0
                            • V Vineela
                              14 Jan 2019, 12:12

                              @jsulm well yes i've done and read the documentation but small thing is item which i added is blank.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 14 Jan 2019, 12:16 last edited by jsulm
                              #14

                              @Vineela First, you need to make sure you parsed Json correctly. The code I posted does not do that!
                              Then please show your current code (reading Json and putting entries into combo box).
                              One more question: are you sure you actually got the reply from server with Json?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              V 1 Reply Last reply 16 Jan 2019, 04:53
                              1
                              • J jsulm
                                14 Jan 2019, 12:16

                                @Vineela First, you need to make sure you parsed Json correctly. The code I posted does not do that!
                                Then please show your current code (reading Json and putting entries into combo box).
                                One more question: are you sure you actually got the reply from server with Json?

                                V Offline
                                V Offline
                                Vineela
                                wrote on 16 Jan 2019, 04:53 last edited by
                                #15

                                @jsulm

                                void MainWindow::datainDaHouse2(QByteArray data)
                                {
                                //first
                                 qDebug()<< "Jason value" +data;
                                 QJsonDocument doc = QJsonDocument::fromJson(data);
                                    QJsonArray array = doc.array();
                                    QJsonObject object = array.at(0).toObject();
                                    QString code = object["LeaderCode"].toString();
                                
                                        ui->comboBox_54->insertItem(3,code);
                                     //second
                                        qDebug()<< "InsertCode" +code;
                                }
                                

                                well this is my current code and my output for qDebug is,
                                //first
                                "Jason value<pre>[\n {\n "LeaderCode": "GNL0001"\n },\n {\n "LeaderCode": "GNL0002"\n }\n]</pre>"
                                //second here where my output getting blank
                                "InsertCode"

                                J 1 Reply Last reply 16 Jan 2019, 05:26
                                0
                                • V Vineela
                                  16 Jan 2019, 04:53

                                  @jsulm

                                  void MainWindow::datainDaHouse2(QByteArray data)
                                  {
                                  //first
                                   qDebug()<< "Jason value" +data;
                                   QJsonDocument doc = QJsonDocument::fromJson(data);
                                      QJsonArray array = doc.array();
                                      QJsonObject object = array.at(0).toObject();
                                      QString code = object["LeaderCode"].toString();
                                  
                                          ui->comboBox_54->insertItem(3,code);
                                       //second
                                          qDebug()<< "InsertCode" +code;
                                  }
                                  

                                  well this is my current code and my output for qDebug is,
                                  //first
                                  "Jason value<pre>[\n {\n "LeaderCode": "GNL0001"\n },\n {\n "LeaderCode": "GNL0002"\n }\n]</pre>"
                                  //second here where my output getting blank
                                  "InsertCode"

                                  J Offline
                                  J Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 16 Jan 2019, 05:26 last edited by
                                  #16

                                  @Vineela Your Json string is invalid as it contains <pre></pre>. You need to remove these HTML tags first.

                                  data = data.replace("<pre>", "").replace("</pre>", "");
                                  QJsonDocument doc = QJsonDocument::fromJson(data);
                                  QJsonArray array = doc.array();
                                  QJsonObject object = array.at(0).toObject();
                                  QString code = object["LeaderCode"].toString();
                                  
                                  ui->comboBox_54->insertItem(3,code);
                                  //second
                                  qDebug()<< "InsertCode" +code;
                                  

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  V 1 Reply Last reply 16 Jan 2019, 05:33
                                  0
                                  • J jsulm
                                    16 Jan 2019, 05:26

                                    @Vineela Your Json string is invalid as it contains <pre></pre>. You need to remove these HTML tags first.

                                    data = data.replace("<pre>", "").replace("</pre>", "");
                                    QJsonDocument doc = QJsonDocument::fromJson(data);
                                    QJsonArray array = doc.array();
                                    QJsonObject object = array.at(0).toObject();
                                    QString code = object["LeaderCode"].toString();
                                    
                                    ui->comboBox_54->insertItem(3,code);
                                    //second
                                    qDebug()<< "InsertCode" +code;
                                    
                                    V Offline
                                    V Offline
                                    Vineela
                                    wrote on 16 Jan 2019, 05:33 last edited by
                                    #17

                                    @jsulm yes i got this "InsertCodeGNL0001" but wat abt GNL0002??

                                    J 1 Reply Last reply 16 Jan 2019, 05:35
                                    0
                                    • V Vineela
                                      16 Jan 2019, 05:33

                                      @jsulm yes i got this "InsertCodeGNL0001" but wat abt GNL0002??

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 16 Jan 2019, 05:35 last edited by
                                      #18

                                      @Vineela Come on! If you get GNL0001 via array.at(0) then you get GNL0002 via array.at(1)...

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      V 1 Reply Last reply 16 Jan 2019, 05:36
                                      0
                                      • J jsulm
                                        16 Jan 2019, 05:35

                                        @Vineela Come on! If you get GNL0001 via array.at(0) then you get GNL0002 via array.at(1)...

                                        V Offline
                                        V Offline
                                        Vineela
                                        wrote on 16 Jan 2019, 05:36 last edited by
                                        #19

                                        @jsulm i know but can't i add it within this line
                                        QJsonObject object = array.at(0).toObject(); so i have to write another object2

                                        J 1 Reply Last reply 16 Jan 2019, 05:38
                                        0
                                        • V Vineela
                                          16 Jan 2019, 05:36

                                          @jsulm i know but can't i add it within this line
                                          QJsonObject object = array.at(0).toObject(); so i have to write another object2

                                          J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 16 Jan 2019, 05:38 last edited by
                                          #20

                                          @Vineela

                                          object = array.at(1).toObject();
                                          QString code = object["LeaderCode"].toString();
                                          ui->comboBox_54->insertItem(3,code);
                                          //second
                                          qDebug()<< "InsertCode" +code;
                                          

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          V 2 Replies Last reply 16 Jan 2019, 05:40
                                          0

                                          1/30

                                          11 Jan 2019, 04:45

                                          • Login

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