我想用計時器每秒讀取一行文件。一旦定時器啓動,讀取第一行,一秒鐘後,讀取第二行......如何在當時使用QTextStream readline之一,使用計時器
但是沒有函數來讀取QTextStream中的特定行。任何想法如何實現這一目標?
如果我運行下面的代碼,它總是會返回
QTextStream: no device QTextStream: no device QTextStream: no device QTextStream: no device
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(sendmsg()));
void simulatorwindow::on_simON_clicked()
{
simfile = QFileDialog::getOpenFileName(this, tr("Open"),"", tr("Files (*.txt)"));
QFile simfile(simfile);
if (!simfile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream textsim(&simfile);
timer->start(1000);
qDebug("Start simulation");
}
void simulatorwindow::on_simOFF_clicked()
{
timer->stop();
qDebug("Stop simulation");
}
void simulatorwindow::sendmsg()
{
QString line = textsim.readLine();
QString title = line.section(',', 0,0);
QString chopped = line.section(',', 1,1);
}