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. Byteordermark is not set in *.csv file
Forum Updated to NodeBB v4.3 + New Features

Byteordermark is not set in *.csv file

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 522 Views
  • 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.
  • H Offline
    H Offline
    hkottmann
    wrote on last edited by
    #1

    Im currently programming with Qt 6.31 an I've recognized that the ByteOrderMark is not set even if I call setGenerateByteOrderMark(true). Here my code:

    QTextStream out(&file);
    out.setGenerateByteOrderMark(true);
    

    In past version of Qt this was always set correctly

    Christian EhrlicherC 1 Reply Last reply
    0
    • H hkottmann

      Im currently programming with Qt 6.31 an I've recognized that the ByteOrderMark is not set even if I call setGenerateByteOrderMark(true). Here my code:

      QTextStream out(&file);
      out.setGenerateByteOrderMark(true);
      

      In past version of Qt this was always set correctly

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Works fine for me with Qt 6.6:

      int main(int argc, char* argv[])
      {
          QCoreApplication app(argc, argv);
      
          QFile f("D:\\test.txt");
          f.open(QIODevice::WriteOnly);
          QTextStream ts(&f);
          ts.setGenerateByteOrderMark(true);
          ts << QLatin1String("blub");
          f.close();
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 2 Replies Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Works fine for me with Qt 6.6:

        int main(int argc, char* argv[])
        {
            QCoreApplication app(argc, argv);
        
            QFile f("D:\\test.txt");
            f.open(QIODevice::WriteOnly);
            QTextStream ts(&f);
            ts.setGenerateByteOrderMark(true);
            ts << QLatin1String("blub");
            f.close();
        }
        
        H Offline
        H Offline
        hkottmann
        wrote on last edited by
        #3

        @Christian-Ehrlicher So it's obviously a bug in Qt 6.31

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Works fine for me with Qt 6.6:

          int main(int argc, char* argv[])
          {
              QCoreApplication app(argc, argv);
          
              QFile f("D:\\test.txt");
              f.open(QIODevice::WriteOnly);
              QTextStream ts(&f);
              ts.setGenerateByteOrderMark(true);
              ts << QLatin1String("blub");
              f.close();
          }
          
          H Offline
          H Offline
          hkottmann
          wrote on last edited by
          #4

          I've tried Qt 6.42. Same thing here

          Christian EhrlicherC 1 Reply Last reply
          0
          • H hkottmann

            I've tried Qt 6.42. Same thing here

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @hkottmann I doubt there is a problem in 6.3/6.4 but fixed in 6.6 without any hint in the bug reporting system. Please try my example and properly look in the output if there is really no bom. How do you check for the bom existance?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hkottmann
              wrote on last edited by
              #6

              Rapidcsv was the evildoer, it removes the BOM. But it's the most efficient library to add the end date of the header of csv file which contains the the data recording of a huge amount of data. So here my solution which I put in a QFuture:

              qint64 SmartDCPD::processDataFile(const QString &fileName)
              {
                  QElapsedTimer t;
                  t.start();
                  QString tempfile = fileName + ".tmp";
                  rapidcsv::Document doc(fileName.toUtf8().constData(), rapidcsv::LabelParams(-1, -1), rapidcsv::SeparatorParams(';'));
                  QString stamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
                  doc.SetCell<std::string>(1, 2, stamp.toUtf8().constData());
                  doc.Save();
                  QFile::rename(fileName, tempfile);
                  QFile file(tempfile);
                  file.open(QIODevice::ReadOnly);
                  QTextStream str(&file);
                  QFile f(fileName);
                  f.open(QIODevice::WriteOnly);
                  QTextStream ts(&f);
                  ts.setGenerateByteOrderMark(true);
                  ts << str.readAll();
                  f.close();
                  file.close();
                  QFile::remove(tempfile);
                  return t.nsecsElapsed();
              }
              
              JonBJ 1 Reply Last reply
              0
              • H hkottmann

                Rapidcsv was the evildoer, it removes the BOM. But it's the most efficient library to add the end date of the header of csv file which contains the the data recording of a huge amount of data. So here my solution which I put in a QFuture:

                qint64 SmartDCPD::processDataFile(const QString &fileName)
                {
                    QElapsedTimer t;
                    t.start();
                    QString tempfile = fileName + ".tmp";
                    rapidcsv::Document doc(fileName.toUtf8().constData(), rapidcsv::LabelParams(-1, -1), rapidcsv::SeparatorParams(';'));
                    QString stamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz");
                    doc.SetCell<std::string>(1, 2, stamp.toUtf8().constData());
                    doc.Save();
                    QFile::rename(fileName, tempfile);
                    QFile file(tempfile);
                    file.open(QIODevice::ReadOnly);
                    QTextStream str(&file);
                    QFile f(fileName);
                    f.open(QIODevice::WriteOnly);
                    QTextStream ts(&f);
                    ts.setGenerateByteOrderMark(true);
                    ts << str.readAll();
                    f.close();
                    file.close();
                    QFile::remove(tempfile);
                    return t.nsecsElapsed();
                }
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @hkottmann said in Byteordermark is not set in *.csv file:

                Rapidcsv was the evildoer

                But how did this differ between Qt versions, 5 vs 6?

                1 Reply Last reply
                1

                • Login

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