Results 1 to 2 of 2

Thread: Appending data, if file exists.

  1. #1
    Join Date
    Oct 2015
    Posts
    35
    Thanks
    11
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Appending data, if file exists.

    Hello All,

    Please take a look at the following code. I have the following 2 questions.

    Qt Code:
    1. FILE *filename1;
    2.  
    3. void MainWindow::update1(void)
    4. {
    5.  
    6. //something
    7. //something
    8.  
    9. filename1 = fopen(filename.toLocal8Bit(),"a");
    10.  
    11. //something
    12. }
    13.  
    14. void MainWindow::on_checkBox_clicked()
    15. {
    16.  
    17. if(ui->checkBox->isChecked())
    18. {
    19.  
    20. filename = QFileDialog::getSaveFileName(...)
    21. /*I'm creating a file when the checkBox is checked. When the checkBox is unchecked and checked back again, If the user selects existing file I want to append data
    22. instead of creating a new file. How do I do it?*/
    23.  
    24. if(!ui->checkBox->isChecked()){
    25.  
    26. //I want to append empty lines to the file a created above and close it. How can I do that?
    To copy to clipboard, switch view to plain text mode 

    Please help. Thanks in advance.

  2. #2
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Appending data, if file exists.

    Qt Code:
    1. if(ui->checkBox->isChecked())
    2. {
    3. filename = QFileDialog::getSaveFileName(...);
    4. file = new QFile(filename);
    5. file->open(QIODevice::Append | QIODevice::Text))
    6. {
    7. qDebug() << "File opened in append mode" << filename;
    8. }
    9. }
    10.  
    11. if(!ui->checkBox->isChecked())
    12. {
    13. QTextStream fout(file);
    14. fout << '\n' << '\n' << '\n';
    15. file->close();
    16. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Vikram.Saralaya for this useful post:

    rookee (10th December 2015)

Similar Threads

  1. Appending data to the buffer of a QAudioOutput
    By PLM in forum Qt Programming
    Replies: 6
    Last Post: 19th August 2013, 04:01
  2. Replies: 2
    Last Post: 21st February 2011, 15:52
  3. Appending text to a file
    By janus in forum General Programming
    Replies: 8
    Last Post: 25th March 2009, 12:23
  4. data is not appending to the file
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 3rd April 2008, 13:39
  5. Replies: 2
    Last Post: 17th November 2006, 12:25

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.