Results 1 to 4 of 4

Thread: Problems saving a text file

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems saving a text file

    Hi
    I've written the following code
    Qt Code:
    1. QString filename;
    2. filename = QFileDialog::getSaveFileName(this,"Choose where to save","","*.jobs");
    3. if (!filename.isEmpty()){
    4. QFile file(filename);
    5. if (file.open(QFile::WriteOnly)){
    6. QTextStream out(&file);
    7. out.setCodec("ISO 8859-1");
    8. out << ui->teScript->toPlainText();
    9. file.close();
    10. }
    11. else
    12. QMessageBox::critical(this,"Error opening file",filename + "\ncould not be opened",QMessageBox::Ok);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Where teScript is a QTextEdit. So If I write something like (on the text edit, when executing the program):

    Hello
    my name is
    John
    Smith

    and then I open the generated txt file (with notepad) i get every line concatenated with a strange square character in the middle.

    So I was wondering how I could possibly fix this problem?
    PS: The problem is in Windows.

  2. #2
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems saving a text file

    change line 5 with this:

    Qt Code:
    1. if (file.open(QFile::WriteOnly|QFile::Text))
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problems saving a text file

    just wondering: why are you using ISO 8859-1? If there is no real reason, I would change it to UTF-8. That could save you a lot of pain if you later need other languages used in your application...

  4. #4
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems saving a text file

    Hi

    I wasn't using the ISO standard. I added the line just to see if the problem was gone. As it turns out I didn't need to fix the problem.

    But thanks for the answer.

Similar Threads

  1. Replies: 8
    Last Post: 8th May 2012, 09:39
  2. Problems with nmake: vc90.pdb header file incorrect
    By deville75 in forum Installation and Deployment
    Replies: 1
    Last Post: 28th July 2009, 22:00
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. Replies: 2
    Last Post: 17th November 2006, 11:25
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.