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. QIODevice::Append is not working as expected

QIODevice::Append is not working as expected

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

    using QT 4.8 in QtCreator.

    I want to append a new line to a text file every time I open and write and close. But this code is overwriting the line that is already in the file.

    QFile efile;
        QString filepath = "/home/user12/cal/logs/Sensor_" + sensor + "_Temp_" + QString::number(CURTEMP*10) + "_LOG.log";
    
        QFile efile(filepath);
        if(efile.open(QIODevice::WriteOnly) | QIODevice::Append)
        {
            QTextStream qts(&efile);
            if(validIn)
            {
                qts << "(Pre-Temp Setup) For Power Level " << (countIn - qAbs(MinCW_PowerLevel)) << ": Pre-Amp Power = " << PreAmpPowerLevelArray[PowerLevelCount] << " and Power Meter = " << meterReading << " (VALID)\n";
            }else if(!validIn)
            {
                qts << "(Pre-Temp Setup) For Power Level " << (countIn - qAbs(MinCW_PowerLevel)) << ": Pre-Amp Power = " << PreAmpPowerLevelArray[PowerLevelCount] << " and Power Meter = " << meterReading << " (INVALID)\n";
            }
    
            qDebug()<<"file open";
    
        }
        efile.close();
    
    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qt_emp
      wrote on last edited by
      #2

      Nevermind. I found it, a badly placed closing parenthesis in the if(efile.open line.

      Thanks all

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Glad you found out and thanks for sharing !

        Please mark the thread as solved so that other forum users may know a solution has been found :-)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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