//In MainWindow.cpp
{
ui->setupUi(this);
Api *ap = new Api(this);
}
void MainWindow::updateValues()
{
connect(timer, SIGNAL(timeout()), this, SLOT(findUpdate()));
timer->start(1000);
}
//I call multiple functions from api
void MainWindow::findUpdate()
{
api->getData(url);
api->getData1(url);
}
//In api.h file QNetworkAcessManager manager;
//In api.cpp
{
QNetworkRequest request
(QUrl(url
));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata()));
}
void Api::replyData()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.array();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit listOfValues(list);
}
{
QNetworkRequest request
(QUrl(url
));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata1()));
}
void Api::replyData1()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit listOfValues(list);
}
//In MainWindow.cpp
void MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),UI(new Ui::MainWindow)
{
ui->setupUi(this);
Api *ap = new Api(this);
}
void MainWindow::updateValues()
{
QTimer* timer=new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(findUpdate()));
timer->start(1000);
}
//I call multiple functions from api
void MainWindow::findUpdate()
{
api->getData(url);
api->getData1(url);
}
//In api.h file QNetworkAcessManager manager;
//In api.cpp
void Api::getData(QString url)
{
QNetworkRequest request(QUrl(url));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata()));
}
void Api::replyData()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
if(reply)
{
QString response = (QString)reply.realAll();
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.array();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit listOfValues(list);
}
void Api::getData1(QString url)
{
QNetworkRequest request(QUrl(url));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata1()));
}
void Api::replyData1()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
if(reply)
{
QString response = (QString)reply.realAll();
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit listOfValues(list);
}
To copy to clipboard, switch view to plain text mode
d
Bookmarks