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. Problems writing a txt file
Forum Updated to NodeBB v4.3 + New Features

Problems writing a txt file

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    darkp03
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Use QTextStream instead of QDataStream.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        darkp03
        wrote on last edited by
        #3

        Thx, that fixed it!

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

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