Show real StartFunction1.
Sure.
void MainWindow::StartFunction1()
{
//Actualize
m_dataPath.
setFilter(QDir::Files);
DownloaderDLL *d = new DownloaderDLL;
foreach
(QString filename, m_dataPath.
entryList()) {
strID.replace("_",".");
d->doDownload(strID);
}
m_DownloadComplete = true;
}
void MainWindow::StartFunction1()
{
//Actualize
m_dataPath.setFilter(QDir::Files);
m_dataPath.setNameFilters(QStringList() << "*.csv");
QString strID;
DownloaderDLL *d = new DownloaderDLL;
foreach (QString filename, m_dataPath.entryList())
{
strID = QFileInfo(filename).baseName();
strID.replace("_",".");
d->doDownload(strID);
}
m_DownloadComplete = true;
}
To copy to clipboard, switch view to plain text mode
void DownloaderDLL
::doDownload(QString str_ID
) {
m_strID=str_ID;
m_strValues="nabl1c1p2t1d1";
url = "http://download.finance.yahoo.com/d/quotes.csv?s=" + m_strID + "&f=" + m_strValues + "&e=.csv";
reply = manager.get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()),
this, SLOT(replyFinished()));
}
void DownloaderDLL::replyFinished ()
{
if(reply->error())
{
file->remove();
tr("Download failed: %1.")
.arg(reply->errorString()));
}
else
{
strContent = reply->readAll();
if (strContent.contains("N/A"))
{
tr("Could not find ID: %1. \nPlease try again")
.arg(m_strID));
}
else
{
m_strID.replace(".","_");
file = new QFile(QDir::currentPath() + "\\data\\watchlist\\stocks\\" + m_strID
+ ".csv");
if(file
->open
(QFile::Append)) {
file->write(strContent);
tr("Download finished to following path: %1.")
.arg(file->fileName()));
file->flush();
file->close();
}
}
}
reply->deleteLater();
reply = 0;
delete file;
file = 0;
}
void DownloaderDLL::doDownload(QString str_ID)
{
m_strID=str_ID;
m_strValues="nabl1c1p2t1d1";
url = "http://download.finance.yahoo.com/d/quotes.csv?s=" + m_strID + "&f=" + m_strValues + "&e=.csv";
reply = manager.get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()),
this, SLOT(replyFinished()));
}
void DownloaderDLL::replyFinished ()
{
if(reply->error())
{
file->remove();
QMessageBox::warning(NULL, tr("Download data"),
tr("Download failed: %1.")
.arg(reply->errorString()));
}
else
{
QByteArray strContent;
strContent = reply->readAll();
if (strContent.contains("N/A"))
{
QMessageBox::warning(NULL, tr("Download data"),
tr("Could not find ID: %1. \nPlease try again")
.arg(m_strID));
}
else
{
m_strID.replace(".","_");
file = new QFile(QDir::currentPath() + "\\data\\watchlist\\stocks\\" + m_strID + ".csv");
if(file->open(QFile::Append))
{
file->write(strContent);
QMessageBox::information(NULL, tr("Download data"),
tr("Download finished to following path: %1.")
.arg(file->fileName()));
file->flush();
file->close();
}
}
}
reply->deleteLater();
reply = 0;
delete file;
file = 0;
}
To copy to clipboard, switch view to plain text mode
StartFunction1 scans for *.csv files with special ID filenames. This IDs can be used to determine and extract stock values from yahoo. I append actual data to the *.csv files. In the next step i want to scan all *.csv files and extract actual data to show them in a gui. The problem is that the second scan is proceeded before downloading is finished.
Maybe i could implement the second step within "replyFinished" for each value avoid that problem.
Bookmarks