Read a file txt
-
QByteArray accumulatedData; QByteArray expectedEnd= QByteArray::fromHex("2320"); void MainWindow::updateGUI_sonde(QByteArray data_sonde) { qDebug() << Q_FUNC_INFO << data_sonde.toHex(' '); // <------ this one accumulatedData.append(data_sonde); if(!accumulatedData.endsWith(expectedEnd)) return; //ecrire les données*********************** QFile file("data_sonde.txt"); QStringList line_data ; if( file.open(QIODevice::Append)) { QTextStream data(&file); data<<accumulatedData; file.close(); //lire les données************************* QStringList line ; if (!file.open(QFile::ReadOnly | QFile::Text)) { qDebug()<<"File not exists"; } else { QTextStream lire_data(&file); lire_data.seek(file.size() - accumulatedData.size()); while (!lire_data.atEnd()) { qDebug() << lire_data.readLine(); } file.close(); } } accumulatedData.clear(); //We now clear at the very end }@J-Hilk
Cool but wont he just get the last # and not the data line ? -
@mrjj he shouldn't, wee accumulate the whole message, before we actually write:
void MainWindow::updateGUI_sonde(QByteArray data_sonde) { qDebug() << Q_FUNC_INFO << data_sonde.toHex(' '); // <------ this one accumulatedData.append(data_sonde); if(!accumulatedData.endsWith(expectedEnd)) return; -
@mrjj he shouldn't, wee accumulate the whole message, before we actually write:
void MainWindow::updateGUI_sonde(QByteArray data_sonde) { qDebug() << Q_FUNC_INFO << data_sonde.toHex(' '); // <------ this one accumulatedData.append(data_sonde); if(!accumulatedData.endsWith(expectedEnd)) return;@J-Hilk @mrjj thank you it works very well