PDA

View Full Version : Read live stock quoted from a website using qt4 c++?



abghosh
20th February 2010, 02:29
Hi
I want to read all the information available from the website "http://www.nseindia.com/marketinfo/comp… about the stock DLF.

I am using Qt4 C++.
Being a newbie I need some help for the same.

Thanks in Advance.

Archimedes
20th February 2010, 08:00
You need to use these classes QNetworkAccessManager, QNetworkReply, QNetworkRequest to send requests and get a reply where you can manipulate the data you got.
There are some examples in the documentation showing the use of those classes.
Hope to helped a little :)

abghosh
20th February 2010, 20:59
I have tried it. But am not able to read the data into string. Below is my code. Can u tell what is the error that I am doing...

QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl("http://mobile.flightview.com/TrackByFlight.aspx"));
QNetworkReply *reply = manager->get(request);
textArea = new QTextBrowser;
if (reply->error() == QNetworkReply::NoError){
textArea->setText("[" + QDateTime::currentDateTime().toString() + "] :: "\
"The file has been successfully read from the network");
textArea->append("[" + QDateTime::currentDateTime().toString() + "] :: "\
"URL Used: " + reply->url());
QByteArray bytes = reply->readAll();
QString string = QString::fromUtf8(bytes);
QString Temp_1;
Temp_1 = string.section(",", 0,0);
textArea->append("[" + QDateTime::currentDateTime().toString() + "] :: "\
"Reply size: \n" + reply->error());
textArea->append("[" + QDateTime::currentDateTime().toString() + "] :: "\
"Line Read :\t" + Temp_1);
}else{
textArea->append("[" + QDateTime::currentDateTime().toString() + "] :: "\
"There is an error reading from network...");
}

squidge
20th February 2010, 23:29
The call is asynchronous - use a slot.

abghosh
21st February 2010, 03:08
Thanks fatjuicymole. It works fine now. I have to now parse the html code to get the desired output.