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