mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
try to implement timeouts support to quotes (ref to #54)
This commit is contained in:
parent
b51c97abbb
commit
f534a6854a
@ -24,7 +24,6 @@
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
#include <QTime>
|
||||
|
||||
@ -243,7 +242,8 @@ QMap<QString, float> ExtQuotes::run()
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
|
||||
manager->get(QNetworkRequest(QUrl(url())));
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
new QReplyTimeout(reply, 1000);
|
||||
}
|
||||
|
||||
// update value
|
||||
|
@ -20,11 +20,29 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
|
||||
#define YAHOO_URL "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol=\"$TICKER\"&env=store://datatables.org/alltableswithkeys&format=json"
|
||||
|
||||
|
||||
class QNetworkReply;
|
||||
class QReplyTimeout : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QReplyTimeout(QNetworkReply *reply, const int timeout) : QObject(reply)
|
||||
{
|
||||
QTimer::singleShot(timeout, this, SLOT(timeout()));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void timeout()
|
||||
{
|
||||
QNetworkReply *reply = static_cast<QNetworkReply *>(parent());
|
||||
if (reply->isRunning()) reply->close();
|
||||
}
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class ExtQuotes;
|
||||
|
Loading…
Reference in New Issue
Block a user