QT 4.7从Yahoo Finances获取CSV文件

时间:2014-03-01 20:43:30

标签: c++ qt csv yahoo-finance

我正在尝试使用Gt 4.7在我的程序中使用GET从Yahoo Finances下载CSV文件。

YahooDataLoader::YahooDataLoader(QObject *parent): QObject(parent)
{
    manager = new QNetworkAccessManager(this);

    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(printNewData(QNetworkReply*)));
}

void YahooDataLoader::getDataForCompany(QString companyName, QDate startDate, QDate endDate) {

    QString string("http://ichart.finance.yahoo.com/table.csv?s=GOOG&a=00&b=1&c=2014&d=02&e=1&f=2014");

    QNetworkRequest request;
    request.setUrl(QUrl(string));

    manager->get(request);
}

void YahooDataLoader::printNewData(QNetworkReply* reply) {

    QByteArray bytes = reply->readAll();
    QString string = QString::fromUtf8(bytes);

    Reporter::getInstance()->logMessage(string);
}

不幸的是,我没有收到任何回复,我的意思是没有调用printNewData()。我认为网址是正确的......你看到了什么问题吗?

1 个答案:

答案 0 :(得分:0)

YahooDataLoader* loader = new YahooDataLoader(0);
loader->getDataForCompany("", QDate(), QDate());

输出:
"日期,开盘价,最高价,最低价,收盘价,成交量,收盘价 2014-02-28,1220.34,1224.19,1206.22,1215.65,2313600,1215.65 2014-02-27,1218.39,1224.23,1217.01,1219.21,1260000,1219.21 2014-02-26,1224.00,1228.88,1213.76,1220.17,1982200,1220.17 2014-02-25,1215.94,1224.50,1210.42,1220.00,1438700,1220.00 2014-02-24,1205.36,1220.16,1205.10,1212.51,1674300,1212.51 2014-02-21,1207.81,1209.87,1202.84,1203.79,1862300,1203.79 2014-02-20,1203.14,1206.89,1200.22,1204.11,1700800,1204.11 2014-02-19,1205.30,1209.22,1197.50,1202.34,2103600,1202.34 2014-02-18,1201.41,1212.87,1200.00,1210.88,2108900,1210.88 2014-02-14,1195.61,1204.39,1192.80,1202.80,2186700,1202.80

如您所见,您的代码在我的计算机上运行良好。也许你在代码中忘记了getDataForCompany函数调用?