Results 1 to 3 of 3

Thread: HOw to insert end of line while appending text in a file

  1. #1
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default HOw to insert end of line while appending text in a file

    I am trying to put several lines in a file. But want to insert end of line after every message. I have tried endl and \n but it doesnot work

    the code is as
    Qt Code:
    1. void steg::imagefileopen()
    2. {
    3.  
    4. QString datafilename=ui.datalineEdit->text();
    5. QFileInfo info1(datafilename);
    6.  
    7. QFileDialog* fd = new QFileDialog( this);
    8. fd->setFileMode( QFileDialog::AnyFile );
    9.  
    10. QString s = QFileDialog::getOpenFileName(this,"Choose a IMAGE file to open","image_bank","All Files (*.*)");
    11.  
    12. ui.imagelineEdit->insert(s);
    13. QFileInfo info(s);
    14. QString yes="THE DATA FILE CAN BE HIDDEN IN THE SELECTED IMAGE FILE ";
    15. QString no ="THE DATA FILE IS TOO LARGE TO BE HIDDEN IN THE SELECTED "
    16. "IMAGE FILE.CHOOSE LARGER IMAGE FILE ELSE CHOOSE SMALLER DATA FILE";
    17. QString u = " The size of the image file is ";
    18. v.setValue(info.size());
    19. QString t = v.toString();
    20.  
    21. QString y = " bytes";
    22. u.append(t);
    23. u.append(y);
    24.  
    25. if ( (0.10* info.size())>=(info1.size()))
    26.  
    27. u.append(yes);
    28. else
    29. u.append (no);
    30.  
    31. QFile size_file;
    32. size_file.setFileName("sizeofdatafile.html");
    33. size_file.open(QIODevice::Append);
    34.  
    35. QTextStream out(&size_file);
    36. out << u;
    37. size_file.close();
    38. ui.textBrowser->clear();
    39. QUrl myurl5;
    40. myurl5=QUrl::fromLocalFile( "sizeofdatafile.html" ) ;
    41. ui.textBrowser->setSource(myurl5);
    42. }
    To copy to clipboard, switch view to plain text mode 

    am I missing something.
    i know it should be easy
    But somehow I am not ableto get it
    Last edited by jacek; 17th November 2006 at 12:23. Reason: wrapped too long line

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HOw to insert end of line while appending text in a file

    Adding '\n' works fine for me.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HOw to insert end of line while appending text in a file

    1. You are working with HTML, so \n is treated as a whitespace. Try adding <br/> tag.
    2. Instead of creating a file on disk, you can store that message in a QString and then display it with ui.textBrowser->setHtml( message );

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Detecting the last empty line in a file
    By Ti_Thom in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2006, 06:14
  3. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 19:42
  4. Replies: 13
    Last Post: 21st June 2006, 22:22
  5. How to get text of last line only in QTextEdit?
    By rajesh in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2006, 14:37

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.