How to get Json value from an api and display it in a GUI
-
In this line I'm Getting the error
his->ui->textBrowser->setText(value);
the error:
error: no viable conversion from 'QJsonValue' to 'const QString'
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" :/@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....
-
In this line I'm Getting the error
his->ui->textBrowser->setText(value);
the error:
error: no viable conversion from 'QJsonValue' to 'const QString'
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" :/@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 typeQJsonValue
. You already know that's not a string and how to convert it because you haveqDebug() << " value is" << value.toString();;
-
@JonB
yeah I'm sorry that is because my line was out side the bracket in my computerlike this :
}); this->ui->textBrowser->setText(value); } }
-
@JonB
yeah I'm sorry that is because my line was out side the bracket in my computerlike this :
}); this->ui->textBrowser->setText(value); } }
@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.
-
Thanks the error is gone but it showed nothing on the text browser
-
Thanks the error is gone but it showed nothing on the text browser
@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. -
@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.@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
-
@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
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.
-
@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
@MehdiMak96
QNetworkAccessManager m_manager
has to "persist"/"be in existence"/"not go out of scope" until after the slot you attached to the reply'sfinished
signal has completed.In an earlier post I made a suggestion as to what you could do about it.
-
This post is deleted!