Results 1 to 4 of 4

Thread: Append inserting random char into beginning of QTString

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Append inserting random char into beginning of QTString

    Hello everyone, I'm making a small program that will ease the process of opening files at the law firm I work for. Anyways, I'm having a difficult time with the append class of QTString.

    I am trying to write to a csv file through user input, but need to get past this step first. (everything but 1 will be through user input, and date will take the system date)

    The specific format it needs to look like is:
    ,"defendant",advs.,"plaintiff",Lawyer,1,date,,, ,,,

    The function:
    Qt Code:
    1. void csvWriting()
    2. {
    3. QFile file("register.csv");
    4. file.open(QIODevice::Append | QIODevice::Text);
    5. QDataStream out(&file);
    6. QString string = " ,";
    7. QString defendant = "Defendant";
    8. QString camma = ",";
    9. QString advs = "advs.";
    10. QString plaintiff = "Plaintiff";
    11. QString lawyer = "lawyer";
    12. QString date = "date";
    13. QString ending = ", , , , , \n";
    14. string.append(defendant + camma + advs + camma + plaintiff + camma + lawyer + camma + date + ending);
    15. out << string;
    16. file.close();
    17. }
    To copy to clipboard, switch view to plain text mode 

    However, when it outputs, a random character (seems to like b/d) is inserted into the string:

    d , D e f e n d a n t , a d v s . , P l a i n t i f f , l a w y e r , d a t e , , , , ,
    I'm assuming it has something to do with the appending process as when I was doing the test writing with a single string this did not happen. Does a "," have an escape character I could use instead? The subsequent "," that are appending don't produce this outcome though...

    Where is this d coming from, and how would I fix it? As a side note, I am not sure why all the letters have spaces between them, but, for my purposes, it doesn't seem to matter.

    (perhaps it would just be easier to do "out << string; out << camma;" etc.)
    Last edited by TomJoad; 22nd March 2011 at 16:43.

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  2. qt from beginning to advanced
    By sachinmcajnu in forum Newbie
    Replies: 4
    Last Post: 8th March 2011, 07:58
  3. QDockWidget floating at the beginning
    By Caius Aérobus in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 13:15
  4. Replies: 1
    Last Post: 7th April 2010, 16:26
  5. Cannot append to QFile using QIODevice::Append
    By philwinder in forum Qt Programming
    Replies: 4
    Last Post: 17th November 2008, 09:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.