Problems writing a txt file



  • Hi everybody!
    Im having trouble writing a txt file.
    Im supposed to keep a log on my program, and each time a certain "event" happens, im supposed to write it on a txt file, with the date and time.
    The program works, but i dont know why, it adds a couple of strange characters at the beggining of each line.

    This is my code:

    @
    void Grabador::escribir_log(QString data)
    {
    QFile log("log.txt");
    log.open(QIODevice::Append|QIODevice::WriteOnly);
    QDataStream out(&log);
    out<<data.toAscii();
    log.close();
    }
    @

    ive debugged the program and im sure that the information on data is correct.
    But after i run the program, this is how my log looks like

    http://s11.postimage.org/5420u1s9v/20121221_095922.jpg



  • Use QTextStream instead of QDataStream.



  • Thx, that fixed it!



  • You're welcome. QDataStream places some information in front of each item in case it is required to correctly deserialize the item (for example the length of the string as in your case).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.