Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read a file txt
Forum Updated to NodeBB v4.3 + New Features

Read a file txt

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 4 Posters 3.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J.HilkJ J.Hilk
    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
    }
    
    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #21

    @J-Hilk
    Cool but wont he just get the last # and not the data line ?

    J.HilkJ 1 Reply Last reply
    0
    • mrjjM mrjj

      @J-Hilk
      Cool but wont he just get the last # and not the data line ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #22

      @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;
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      L 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @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;
        
        L Offline
        L Offline
        LatitudeFr
        wrote on last edited by
        #23

        @J-Hilk @mrjj thank you it works very well

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved