Results 1 to 6 of 6

Thread: Strage problem Writing to a Notepad file

  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Strage problem Writing to a Notepad file

    Hello every one. I have a small problem i am writing to a notepad file every 30 seconds. Everything works fine but after some time there is some extra text written after the end of file i am actually updating the file with temperature data which i acquire and dumb into data base.

    Qt Code:
    1. void datadisplay::datatcplog()
    2. {
    3. newfilenames = newdatpath; //"E:/DataLog/"+ QDateTime::currentDateTime().toString("ddd dd-MM-yyyy, hh.mm") +".txt";
    4.  
    5. QSqlQuery sq1("SELECT "+ colames +" FROM thdata where rowid = (select max(rowid) from thdata)");
    6.  
    7. while(sq1.next())
    8. {
    9. for (int i = 0; i < ntnewtempchnames.count(); i++)
    10. {
    11. txtdata.push_back(sq1.value(i).toString());
    12. }
    13. }
    14.  
    15. qDebug()<<"NotePad Log file Temperature Data:"<< txtdata;
    16.  
    17. QString notepadfl;
    18. notepadfl.clear();
    19. notepadfl.append(QTime::currentTime().toString("hh:mm:ss"));
    20. numbch=ntnewtempchnames.count();
    21.  
    22. file5 = new QFile(newfilenames);
    23. file5->open(QFile::ReadWrite | QFile::Text);
    24.  
    25. QTextStream out8(file5);
    26.  
    27. out8 <<"START OF FACILITY DATA" ;
    28. out8 <<"\n" <<"";
    29. out8<<notepadfl<<' '<<newnote<<"\n";
    30. out8 <<"\n" <<"";
    31.  
    32. out8 <<"VACUUM PARAMETERS";
    33. out8 <<"\n" <<"";
    34. out8 <<"0" <<"";
    35. out8 << vaccumparameters.size();
    36. out8 <<"\n" <<"";
    37.  
    38. out8 <<"\n" <<"";
    39. out8 <<"MOTION SIMULATOR PARAMETERS";
    40. out8 <<"\n" <<"";
    41. out8 <<"0" ;
    42. out8 <<"\n" <<"";
    43.  
    44. out8 <<"AYDIN VECTOR PARAMETERS";
    45. out8 <<"\n" <<"";
    46. out8 <<ntnewtempchnames.count();
    47. out8 <<"\n" <<"";
    48. for(int d = 0;d < ntnewtempchnames.count();d++)
    49. {
    50. out8 << nttempidnames.at(d)<<' '<<txtdata.at(d)<< "\n";
    51. }
    52. out8 <<"\n" <<"";
    53.  
    54. out8 <<"END OF FACILITY DATA";
    55. file5->close();
    56. nttempidnames.clear();
    57. txtdata.clear();
    58. }
    To copy to clipboard, switch view to plain text mode 
    This is the text file which is generated but after some time i get some extra text written more then what i write in the program.
    Qt Code:
    1. START OF FACILITY DATA
    2. 10:21:39
    3. VACUUM PARAMETERS
    4. 0
    5. MOTION SIMULATOR PARAMETERS
    6. 0
    7. AYDIN VECTOR PARAMETERS
    8. 10
    9. TE 5000_1 -120
    10. TE 5000_2 -120
    11. TE 5000_3 -120
    12. TE 5000_4 -120
    13. TE 5000_5 -120
    14. TE 5000_6 -120
    15. TE 5000_7 -120
    16. TE 5000_8 -120
    17. TE 5000_9 -120
    18. TE 5000_10 -120
    19. END OF FACILITY DATA
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. START OF FACILITY DATA
    2. 10:21:39
    3. VACUUM PARAMETERS
    4. 0
    5. MOTION SIMULATOR PARAMETERS
    6. 0
    7. AYDIN VECTOR PARAMETERS
    8. 10
    9. TE 5000_1 -120
    10. TE 5000_2 -120
    11. TE 5000_3 -120
    12. TE 5000_4 -120
    13. TE 5000_5 -120
    14. TE 5000_6 -120
    15. TE 5000_7 -120
    16. TE 5000_8 -120
    17. TE 5000_9 -120
    18. TE 5000_10 -120
    19. END OF FACILITY DATA
    20. // But i get some extra text below after this i am not actually writing any thing after END OF FACILITY DATA but then this extra text is written.
    21. 0
    22. TE 5000_606 -150
    23. TE 5000_626 -150
    24.  
    25. DIRECT THERMOCOUPLE PARAMETERS
    26. 0
    27. END OF FACILITY DATA
    28. TE 5000_606 -10.3
    29. TE 5000_626 -10.3
    30.  
    31. DIRECT THERMOCOUPLE PARAMETERS
    32. 0
    33. END OF FACILITY DATA49.8
    34.  
    35. DIRECT THERMOCOUPLE PARAMETERS
    36. 0
    37. END OF FACILITY DATA
    To copy to clipboard, switch view to plain text mode 

    Don't know whats wrong here. Some can see some thing wrong in the program. ?

    Thank you

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Strage problem Writing to a Notepad file

    try adding these at the end

    Qt Code:
    1. out8 <<"END OF FACILITY DATA";
    2. out8.flush(); // Generally not required
    3. file5->close();
    4. delete file5; // Add this
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Santosh Reddy for this useful post:

    nagabathula (23rd June 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Strage problem Writing to a Notepad file

    Hello Anna thankx for the reply . .. i have added the below code which you suggested, but it din work. There is still some extra data after some 5 updates into the notepad.
    Qt Code:
    1. out8.flush();
    2. file5->close();
    3. delete file5;
    To copy to clipboard, switch view to plain text mode 
    wondering what is happening in the program it looks so simple and plain in the program what can be going wrong at all.

    regrads

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Strage problem Writing to a Notepad file

    Couple of question to help me understand better...
    Is void datadisplay::datatcplog() a slot ?
    Is void datadisplay::datatcplog() is called every 30 sec?
    Do you use file5, out side void datadisplay::datatcplog() function?

  6. #5
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strage problem Writing to a Notepad file

    Quote Originally Posted by nagabathula View Post
    Qt Code:
    1. void datadisplay::datatcplog()
    2. {
    3. file5 = new QFile(newfilenames);
    4. file5->open(QFile::ReadWrite | QFile::Text);
    To copy to clipboard, switch view to plain text mode 
    You should use QFile::WriteOnly instead of QFile::ReadWrite in your case.

  7. The following user says thank you to dbzhang800 for this useful post:

    nagabathula (23rd June 2011)

  8. #6
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Strage problem Writing to a Notepad file

    Yea datatcplog() is a slot. I am calling it with a timer every 30 seconds. I have not used file5 any where else in the program.
    I have another routine of writing to a excel file i have named it file4 and there is no problem at all, it logs into excel with out any extra char's. Its only the notepad file which i have a problem. And all the containers which have the data for notepad file are different from the excel logging data containers so there should be nothing extra i am clearing all the containers at the end of the writing function.

    connect(logtimer, SIGNAL(timeout()), this, SLOT(datatcplog()));

    Added after 6 minutes:


    hi dbzhang800 i have changed as you have suggested. In testing now. !! it seems to work there is nothing extra after 5 minutes of logging will check for longer duration. ..

    Thank you
    Last edited by nagabathula; 23rd June 2011 at 07:32.

Similar Threads

  1. Problem in writing to a file
    By darlene in forum Newbie
    Replies: 9
    Last Post: 18th May 2011, 04:42
  2. Writing to a txt file
    By nagabathula in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2011, 11:59
  3. problem writing an xml file
    By mickey in forum General Programming
    Replies: 1
    Last Post: 28th January 2008, 16:05
  4. Writing a XML file
    By Djony in forum Qt Programming
    Replies: 7
    Last Post: 5th February 2007, 16:23
  5. XML file writing
    By mbjerkne in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 19:04

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.