// header file
MainWindow
{
....
// let's say you want to insert a QString in the table
// cause I'm not sure what you're passing in it
void insertInTable
(QString &toInsert
);
...
public slots:
void getData();
void readData();
...
private:
QString m_finalUrlStr;
// holds the new url QNetworkAccessManager *manager;
...
}
// cpp file
const QString initialUrlStr
= "http://finance.yahoo.com/q?s=";
// Constructor
MainWindow::MainWindow()
{
// initialize m_finalUrlStr to the 1st url you want to send a request
m_finalUrlStr = "http://finance.yahoo.com/q?s=GOOG";
// putting the mem allocation and the connections here, Lykurg described why
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(readData(QNetworkReply*)));
connect(timer, SIGNAL(timeout()), this, SLOT(getData()));
...
}
void MainWindow
::insertInTable(QString &toInsert
) {
m_finalUrlStr.clear(); // clear the previous url
m_finalUrlStr = initialUrlStr;
m_finalUrlStr += toInsert; // you got the new url
...// code that does the insertion in the table
}
//1st Slot
void MainWindow::getData()
{
QNetworkRequest request;
request.
setUrl(QUrl(m_finalUrlStr
));
manager->get(request);
}
//2nd Slot
void MainWindow::readData(QNetworkReply *reply){
connect(reply, SIGNAL(readyRead()), this, SLOT(repaint()));
QString Temp1
= string.
section("<div class=\"hd\"><h2>",
2,
2);
insertInTable(Temp1); // I assume that Temp1 holds the data you want to insert
// in the table, I'm just guessing actually
timer->start(10000);
}
// header file
MainWindow
{
....
// let's say you want to insert a QString in the table
// cause I'm not sure what you're passing in it
void insertInTable(QString &toInsert);
...
public slots:
void getData();
void readData();
...
private:
QString m_finalUrlStr; // holds the new url
QNetworkAccessManager *manager;
QTimer *timer;
...
}
// cpp file
const QString initialUrlStr = "http://finance.yahoo.com/q?s=";
// Constructor
MainWindow::MainWindow()
{
// initialize m_finalUrlStr to the 1st url you want to send a request
m_finalUrlStr = "http://finance.yahoo.com/q?s=GOOG";
// putting the mem allocation and the connections here, Lykurg described why
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(readData(QNetworkReply*)));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(getData()));
...
}
void MainWindow::insertInTable(QString &toInsert)
{
m_finalUrlStr.clear(); // clear the previous url
m_finalUrlStr = initialUrlStr;
m_finalUrlStr += toInsert; // you got the new url
...// code that does the insertion in the table
}
//1st Slot
void MainWindow::getData()
{
QNetworkRequest request;
request.setUrl(QUrl(m_finalUrlStr ));
manager->get(request);
}
//2nd Slot
void MainWindow::readData(QNetworkReply *reply){
QByteArray bytes = reply->readAll();
connect(reply, SIGNAL(readyRead()), this, SLOT(repaint()));
QString string = QString::fromUtf8(bytes);
QString Temp1 = string.section("<div class=\"hd\"><h2>", 2, 2);
insertInTable(Temp1); // I assume that Temp1 holds the data you want to insert
// in the table, I'm just guessing actually
timer->start(10000);
}
To copy to clipboard, switch view to plain text mode
Bookmarks