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
Qt 6.11 is out! See what's new in the release blog

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 12.4k 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.
  • VineelaV Offline
    VineelaV Offline
    Vineela
    wrote on 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"
    }
    ]

    jsulmJ 1 Reply Last reply
    0
    • VineelaV Vineela

      @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"
      }
      ]

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      VineelaV 1 Reply Last reply
      2
      • jsulmJ jsulm

        @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

        VineelaV Offline
        VineelaV Offline
        Vineela
        wrote on last edited by
        #13

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

        jsulmJ 1 Reply Last reply
        0
        • VineelaV Vineela

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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          VineelaV 1 Reply Last reply
          1
          • jsulmJ jsulm

            @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?

            VineelaV Offline
            VineelaV Offline
            Vineela
            wrote on 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"

            jsulmJ 1 Reply Last reply
            0
            • VineelaV Vineela

              @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"

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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

              VineelaV 1 Reply Last reply
              0
              • jsulmJ jsulm

                @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;
                
                VineelaV Offline
                VineelaV Offline
                Vineela
                wrote on last edited by
                #17

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

                jsulmJ 1 Reply Last reply
                0
                • VineelaV Vineela

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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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

                  VineelaV 1 Reply Last reply
                  0
                  • jsulmJ jsulm

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

                    VineelaV Offline
                    VineelaV Offline
                    Vineela
                    wrote on 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

                    jsulmJ 1 Reply Last reply
                    0
                    • VineelaV Vineela

                      @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

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 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

                      VineelaV 2 Replies Last reply
                      0
                      • jsulmJ jsulm

                        @Vineela

                        object = array.at(1).toObject();
                        QString code = object["LeaderCode"].toString();
                        ui->comboBox_54->insertItem(3,code);
                        //second
                        qDebug()<< "InsertCode" +code;
                        
                        VineelaV Offline
                        VineelaV Offline
                        Vineela
                        wrote on last edited by
                        #21

                        @jsulm well I've added this
                        for(int i=0 ;i<array.size();i++){
                        QJsonObject object = array.at(i).toObject();
                        } it worked

                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Vineela

                          object = array.at(1).toObject();
                          QString code = object["LeaderCode"].toString();
                          ui->comboBox_54->insertItem(3,code);
                          //second
                          qDebug()<< "InsertCode" +code;
                          
                          VineelaV Offline
                          VineelaV Offline
                          Vineela
                          wrote on last edited by
                          #22

                          @jsulm object = array.at(1).toObject();
                          I've done this too but got only second one so.

                          jsulmJ 1 Reply Last reply
                          0
                          • VineelaV Vineela

                            @jsulm object = array.at(1).toObject();
                            I've done this too but got only second one so.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #23

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

                            I've done this too but got only second one so

                            Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.

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

                            VineelaV 2 Replies Last reply
                            0
                            • jsulmJ jsulm

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

                              I've done this too but got only second one so

                              Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.

                              VineelaV Offline
                              VineelaV Offline
                              Vineela
                              wrote on last edited by
                              #24

                              @jsulm well thank u so much for your help ,I've done it using for loop it worked.

                              1 Reply Last reply
                              1
                              • jsulmJ jsulm

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

                                I've done this too but got only second one so

                                Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.

                                VineelaV Offline
                                VineelaV Offline
                                Vineela
                                wrote on last edited by
                                #25

                                @jsulm can u suggest here how to make it in ascending order???

                                jsulmJ 1 Reply Last reply
                                0
                                • VineelaV Vineela

                                  @jsulm can u suggest here how to make it in ascending order???

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #26

                                  @Vineela

                                  for(int i = array.size() - 1 ; i >= 0; --i) {
                                      QJsonObject object = array.at(i).toObject();
                                  }
                                  

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

                                  VineelaV 2 Replies Last reply
                                  3
                                  • jsulmJ jsulm

                                    @Vineela

                                    for(int i = array.size() - 1 ; i >= 0; --i) {
                                        QJsonObject object = array.at(i).toObject();
                                    }
                                    
                                    VineelaV Offline
                                    VineelaV Offline
                                    Vineela
                                    wrote on last edited by
                                    #27

                                    @jsulm thanks you've saved my day :D it worked fine.

                                    1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @Vineela

                                      for(int i = array.size() - 1 ; i >= 0; --i) {
                                          QJsonObject object = array.at(i).toObject();
                                      }
                                      
                                      VineelaV Offline
                                      VineelaV Offline
                                      Vineela
                                      wrote on last edited by
                                      #28

                                      @jsulm my data is getting repeated once i come back is that bcoz of my for loop?

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • VineelaV Vineela

                                        @jsulm my data is getting repeated once i come back is that bcoz of my for loop?

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by jsulm
                                        #29

                                        @Vineela Not sure what you mean?
                                        You mean if you get new data and add new entries to your combo box you then have same values several times?
                                        In this case you need to filter new values and only add values which are not yet in the box.

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

                                        VineelaV 1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @Vineela Not sure what you mean?
                                          You mean if you get new data and add new entries to your combo box you then have same values several times?
                                          In this case you need to filter new values and only add values which are not yet in the box.

                                          VineelaV Offline
                                          VineelaV Offline
                                          Vineela
                                          wrote on last edited by
                                          #30

                                          @jsulm yes thnks i cleared the combo box before navigating to that page its ok now

                                          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