Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get Json value from an api and display it in a GUI
Forum Updated to NodeBB v4.3 + New Features

How to get Json value from an api and display it in a GUI

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 6 Posters 782 Views 2 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.
  • M MehdiMak96

    @Christian-Ehrlicher @JonB

    In this line I'm Getting the error

    his->ui->textBrowser->setText(value);
    

    the error:

    error: no viable conversion from 'QJsonValue' to 'const QString'

    @mrjj

    The whole idea is to let the user to choose whatever city in the combobox and show him the "weekIncidence" in that city in a text browser .
    I just figured another problem to right a code that can only read the "weekIncidence" :/

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #10

    @MehdiMak96 said in How to get Json value from an api and display it in a GUI:

    error: no viable conversion from 'QJsonValue' to 'const QString'

    But you wrote earlier that there error message was:

    use of undeclared identifier 'Value'

    ? And got everybody to look for that....

    1 Reply Last reply
    1
    • M MehdiMak96

      @Christian-Ehrlicher @JonB

      In this line I'm Getting the error

      his->ui->textBrowser->setText(value);
      

      the error:

      error: no viable conversion from 'QJsonValue' to 'const QString'

      @mrjj

      The whole idea is to let the user to choose whatever city in the combobox and show him the "weekIncidence" in that city in a text browser .
      I just figured another problem to right a code that can only read the "weekIncidence" :/

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #11

      @MehdiMak96
      Anyway....

      QJsonValue value = obj.value(QString("+name+"));
      this->ui->textBrowser->setText(value);
      
      error: no viable conversion from 'QJsonValue' to 'const QString'
      

      setText(), requires a string. value is type QJsonValue. You already know that's not a string and how to convert it because you have

      qDebug() << " value is" << value.toString();;
      
      1 Reply Last reply
      3
      • M Offline
        M Offline
        MehdiMak96
        wrote on last edited by MehdiMak96
        #12

        @JonB
        yeah I'm sorry that is because my line was out side the bracket in my computer

        like this :

              });
          this->ui->textBrowser->setText(value);
            }
        
        }
        
        JonBJ 1 Reply Last reply
        0
        • M MehdiMak96

          @JonB
          yeah I'm sorry that is because my line was out side the bracket in my computer

          like this :

                });
            this->ui->textBrowser->setText(value);
              }
          
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #13

          @MehdiMak96
          OK, but that's not in the code you showed. And you didn't say anything when you discovered it so we knew.

          Anyway for that new error your post crossed with mine, see my previous post above.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MehdiMak96
            wrote on last edited by
            #14

            Thanks the error is gone but it showed nothing on the text browser

            JonBJ 1 Reply Last reply
            0
            • M MehdiMak96

              Thanks the error is gone but it showed nothing on the text browser

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #15

              @MehdiMak96
              That's down to you. Only you know what is the JSON you are reading. You might put more debugging output in your code, or run it in debugger.

              Also if you have not acted on what has been said about the scope of the QNetworkAccessManager m_manager; you may have problems. But you'll know that from your debugging.

              M 1 Reply Last reply
              1
              • JonBJ JonB

                @MehdiMak96
                That's down to you. Only you know what is the JSON you are reading. You might put more debugging output in your code, or run it in debugger.

                Also if you have not acted on what has been said about the scope of the QNetworkAccessManager m_manager; you may have problems. But you'll know that from your debugging.

                M Offline
                M Offline
                MehdiMak96
                wrote on last edited by
                #16

                @JonB but i have no clue what this means

                    // if in mainwindow. make sure m_manager lives in .h as member. else it wont work. ( death by scope)
                      QNetworkAccessManager m_manager;
                

                can you please explain it to me

                mrjjM JonBJ 2 Replies Last reply
                0
                • M MehdiMak96

                  @JonB but i have no clue what this means

                      // if in mainwindow. make sure m_manager lives in .h as member. else it wont work. ( death by scope)
                        QNetworkAccessManager m_manager;
                  

                  can you please explain it to me

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #17

                  @MehdiMak96

                  Hi
                  I wrote that comment.
                  It means
                  QNetworkAccessManager m_manager; here is a local variable.
                  Those are deleted as soon a function ends.
                  QNetworkAccessManager is asynchronous which means the m_manager might be deleted before
                  the QNetworkReply::finished is fired.

                  So its better to move it to part of Corona_Aktuell class.
                  That is to put it in the .h inside the class. as a class member.

                  Also regarding your json parsing.
                  Do note that the data holding class (the cites) is inside an object called
                  Data. so the current code might be in the wrong json class and hence return nothing
                  for "name" as that one level deeper.

                  Is this school task ? Im asking to know how much we can help without breaking the rules.

                  1 Reply Last reply
                  3
                  • M MehdiMak96

                    @JonB but i have no clue what this means

                        // if in mainwindow. make sure m_manager lives in .h as member. else it wont work. ( death by scope)
                          QNetworkAccessManager m_manager;
                    

                    can you please explain it to me

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #18

                    @MehdiMak96
                    QNetworkAccessManager m_manager has to "persist"/"be in existence"/"not go out of scope" until after the slot you attached to the reply's finished signal has completed.

                    In an earlier post I made a suggestion as to what you could do about it.

                    1 Reply Last reply
                    3
                    • M Offline
                      M Offline
                      MehdiMak96
                      wrote on last edited by
                      #19
                      This post is deleted!
                      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