What does this error mean when getting weather data in Qt5?
Qt obtains weather information
This function mainly relies on the China Weather Network to provide web pages for each place, and uses Qt's network class to intercept the strings on the web page
Step 1: Create two related Qt network class objects
QNetworkAccessManager *manager;
QNetworkReply *reply;
QString city;// String used to get the place
QString weather;//String used to get the weather
public slots:
void getWeather(QNetworkReply *replyweather) ;//Create a new slot here, which will be used in step three
1
2
3
4
p>5
6
1
2
3
4
5
6
Step 2: Get the web pages of each place provided by China Weather Network
QString str("/data/101010100.html" );//The string of numbers inside represents the city code
1
1
Step 3: Set the two objects in step 1
1
1
p>
manager = new QNetworkAccessManager(parent);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(getWeather(QNetworkReply*)));//When obtained After responding, associate to the corresponding slot
QString str("/data/101010100.html");
manager->get(QNetworkRequest(QUrl(str)));// Request a response from this page
1
2
3
4
1
< p>23
4
Step 4: Intercept the string
void DreamWeather::getWeather(QNetworkReply *replayweather)< /p>
{
QTextCodec *codec=QTextCodec::codecForName("utf8");
QString str=codec->toUnicode(replayweather->readAll()) ;//Read out all the obtained requests
//The following is the operation of intercepting web page strings. Specifically why and how to do it, you can go and look at that web page and you will understand
< p> str.replace(QString("{"),QString("+"));QStringList weatherlist=str.split('+');
str=weatherlist .at(list.count()-1);
str.replace(QString("}"),QString(""));
str.replace(QString( "\""),QString(""));
weatherlist=str.split(',');
for(int i=0;i { QString st; QStringList li; st=weatherlist.at(i);< /p> li=st.split(':'); if(li.first()=="city") city=li.at( 1);//Get the local string if(li.first()=="weather1") weather1=li.at(1);//Get the Local weather string } emit finish(true); } //The relevant information obtained will be saved In the string in step 1, that webpage provides a lot of information and can intercept a lot of things