Results 1 to 3 of 3

Thread: data is not appending to the file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy data is not appending to the file

    Hello all,
    i had a problem to access the file operation, when i tried to write something to the file from my GUI(designer file) then it erasing all the data exist in the file and writing only string which i entered in the LineEdit but i want to be append it to the file.
    Here is my code


    Qt Code:
    1. #include<QtCore>
    2. #include<QtGui>
    3. #include"ui_dialog1.h"
    4. #include <stdio.h>
    5.  
    6.  
    7. class synopsys : public QDialog,public Ui::dialog1
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. synopsys()
    13. {
    14. setupUi(this);
    15. connect(pushButton1, SIGNAL(clicked()), this , SLOT(save()));
    16. connect(pushButton2, SIGNAL(clicked()), this , SLOT(close()));
    17.  
    18. }
    19.  
    20. public slots:
    21.  
    22. void save()
    23. {
    24. Qt::CheckState state1,state2,state3,state4;
    25.  
    26. state1 = checkBox1->checkState();
    27. state2 = checkBox2->checkState();
    28. state3 = checkBox3->checkState();
    29. state4 = checkBox4->checkState();
    30.  
    31. if(state1 == Qt::Checked)
    32. {
    33. fileName = "/home/window1/synopsys_startup.txt";
    34. QFile file(fileName);
    35. QString str = lineEdit1->text();
    36.  
    37. const char *ch = str.toLatin1();
    38. file.open(QIODevice::WriteOnly);
    39. file.write(ch, qstrlen(ch));
    40. file.close();
    41.  
    42. }
    43.  
    44.  
    45.  
    46.  
    47. if(state2 == Qt::Checked)
    48. {
    49.  
    50. fileName = "/home/window1/synopsys_startup.txt";
    51. QFile file(fileName);
    52. QString str = lineEdit2->text();
    53.  
    54. const char *ch = str.toLatin1();
    55. file.open(QIODevice::WriteOnly);
    56. file.write(ch, qstrlen(ch));
    57. file.close();
    58.  
    59.  
    60. }
    61.  
    62.  
    63. if(state3 == Qt::Checked)
    64. {
    65.  
    66. fileName = "/home/window1/synopsys_startup.txt";
    67. QFile file(fileName);
    68. QString str = lineEdit3->text();
    69.  
    70. const char *ch = str.toLatin1();
    71.  
    72. file.open(QIODevice::WriteOnly);
    73. file.write(ch, qstrlen(ch));
    74. file.close();
    75.  
    76.  
    77.  
    78. }
    79.  
    80.  
    81. if(state4 == Qt::Checked)
    82. {
    83.  
    84. fileName = "/home/window1/synopsys_startup.txt";
    85. QFile file(fileName);
    86. QString str = lineEdit4->text();
    87.  
    88. const char *ch = str.toLatin1();
    89. file.open(QIODevice::WriteOnly);
    90. file.write(ch, qstrlen(ch));
    91. file.close();
    92.  
    93.  
    94.  
    95. }
    96.  
    97.  
    98. }
    99. private:
    100. QString fileName;
    101.  
    102. };
    103.  
    104. int main(int argc, char *argv[])
    105. {
    106.  
    107. QApplication app(argc,argv);
    108.  
    109. synopsys *startup = new synopsys;
    110. startup->show();
    111.  
    112. return app.exec();
    113. }
    114.  
    115. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    any help or suggestion will be much appreciated
    Last edited by wysota; 3rd April 2008 at 15:58. Reason: missing [code] tags

Similar Threads

  1. Getting sound data from a wave file
    By ko9 in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 11:23
  2. sending encrypted data via mail using smtp
    By vermarajeev in forum General Programming
    Replies: 20
    Last Post: 14th August 2007, 19:47
  3. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Transferring data input from a Widget to a cpp file
    By Ahmad in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2007, 09:59

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.