private: Ui::Widget *ui; int x,y; QString buffer; qint64 line_number;
... QTimer *point_update=new QTimer; connect(point_update, SIGNAL(timeout()),this,SLOT(pointsmath())); point_update->start(1000);...
void Widget:: pointsmath(){ //------------------------------------------------------------------------------------------------- QFile mFile("C:/Test/test.txt"); if(!mFile.open(QFile::ReadOnly|QFile::Text)) { QMessageBox::information(this, "Error", "Путь не правильный"); return; } QTextStream stream(&mFile); qDebug()<<"line_number="<<line_number; y=0; buffer.clear(); buffer=stream.readLine(line_number);// вся проблема в этой строке...наверное y=buffer.toInt(); points << QPointF( x, y); // заполнение x++; y++; line_number++; qDebug()<<"buffer="<<buffer; qDebug()<<x<<"/"<<y; mFile.flush(); mFile.close(); //------------------------------------------------------------------------------------------------------- curve->setSamples( points ); curve->attach( ui->wgtBoss ); }
...line_number= 1 buffer= "1" x= 1 /y= 1 line_number= 2buffer= "1" x= 2 /y= 1 line_number= 3 buffer= "1" x= 3 /y= 1 line_number= 4 buffer= "1" x= 4 /y= 1 ...
C++ (Qt)#include <QtCore> class TestFileRead : public QObject{ Q_OBJECTpublic: TestFileRead(QObject* parent = NULL); ~TestFileRead();private slots: void read();private: QFileSystemWatcher w; QFile* f; QTextStream s;};
C++ (Qt)#include "testfileread.h"#include <QDebug>TestFileRead::TestFileRead(QObject* parent /* = NULL */) : QObject(parent){ f = new QFile("1.txt", this); f->open(QFile::ReadOnly); s.setDevice(f); w.addPath("1.txt"); connect(&w, &QFileSystemWatcher::fileChanged, this, &TestFileRead::read);}TestFileRead::~TestFileRead() { }void TestFileRead::read(){ while (!s.atEnd()) { qDebug(qPrintable(s.readLine())); }}
C++ (Qt)void TestFileRead::read(){ while (!s.atEnd()) { qDebug(qPrintable(s.readLine())); }}