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

QTextStream and transactions



  • Why does not QTextStream support transactions and, hence, the managment of fragmentation, as opposed to QDataStream?



  • QDataStream only provides a convenient interface over the transaction, the actual transaction is handled by the QIODevice directly: https://doc.qt.io/qt-5/qiodevice.html#startTransaction
    You are free to use transactions with QTextStream you just need a couple more lines of code.

    • instead of dataStream.startTransaction() you would use textStream.device()->startTransaction();
    • instead of if(dataStream.commitTransaction()){/*do stuff*/} you would use:
    if(textStream.status() == QTextStream::Ok){
    textStream.device()->commitTransaction();
    /*do stuff*/
    }
    else{
    textStream.device()->rollbackTransaction();
    }
    

Log in to reply