我想用计时器每秒读取一行文件。一旦定时器启动,读取第一行,一秒钟后,读取第二行......如何在当时使用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);
}