Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QIODevice::Append is not working as expected



  • 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();
    


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

    Thanks all


  • Lifetime Qt Champion

    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 :-)


Log in to reply