Results 1 to 8 of 8

Thread: How to save a file in Windows 1250 code

  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default How to save a file in Windows 1250 code

    Hi.

    I have all my data in Utf8, but now I have to save a file in Windows1250 code. How to conversion a data from utf8 to windows 1250 and save file in windows 1250 code?

    Thaks

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save a file in Windows 1250 code

    Have a look at QTextCodec in combination with QTextStream.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save a file in Windows 1250 code

    Could you give me an example, there is only examples to and from Unicode :/

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save a file in Windows 1250 code

    Those are the exact examples you need. toUnicode() returns a QString (QStrings are unicode), fromUnicode() returns a QByteArray, which is your target encoding.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. The following user says thank you to franz for this useful post:

    TomASS (9th February 2010)

  6. #5
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save a file in Windows 1250 code

    Ok, thanks, and what with save file in windows 1250?

  7. #6
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save a file in Windows 1250 code

    Now I have:

    Qt Code:
    1. QString numer_fakt = "222";
    2. QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"),numer_fakt+".epp",tr("Pliki wymiany danych (*.epp)"));
    3. if(fileName.size()==0) return;
    4. QFile file(fileName);
    5. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    6. return;
    7.  
    8. QString dane = "Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ";
    9. QTextCodec *codec = QTextCodec::codecForName("Windows-1250");
    10. QByteArray encodedString = codec->fromUnicode(dane);
    11.  
    12. QTextStream out(&file);
    13. out.setCodec(codec);
    14. out << encodedString;
    15. file.close();
    To copy to clipboard, switch view to plain text mode 

    what's next? in file I've got only ? ? ? ? sings :/
    Last edited by TomASS; 9th February 2010 at 22:34.

  8. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save a file in Windows 1250 code

    Quote Originally Posted by TomASS View Post
    Now I have:

    Qt Code:
    1. QString numer_fakt = "222";
    2. QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"),numer_fakt+".epp",tr("Pliki wymiany danych (*.epp)"));
    3. if(fileName.size()==0) return;
    4. QFile file(fileName);
    5. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    6. return;
    7.  
    8. QString dane = "Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ";
    9. QTextCodec *codec = QTextCodec::codecForName("Windows-1250");
    10. QByteArray encodedString = codec->fromUnicode(dane);
    11.  
    12. QTextStream out(&file);
    13. out.setCodec(codec);
    14. out << encodedString;
    15. file.close();
    To copy to clipboard, switch view to plain text mode 

    what's next? in file I've got only ? ? ? ? sings :/
    Change line 14 with
    Qt Code:
    1. out << dane;
    To copy to clipboard, switch view to plain text mode 
    or replace lines 12-14 with
    Qt Code:
    1. file.write(encodedString();
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save a file in Windows 1250 code

    Line 8 is tricky. You'd better specify the encoding it comes from:

    Qt Code:
    1. QString dane = QString::fromUtf8("Ę Ã“ Ą Ś Ł Ż Ź Ć Ń ę ó ą ś ł ż ź ć ");
    To copy to clipboard, switch view to plain text mode 

    If the source file is utf-8 encoded of course.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. How to save file with QFileDialog
    By pnikolov in forum Qt Programming
    Replies: 11
    Last Post: 1st June 2012, 10:23
  2. Save file dialog
    By yxtx1984 in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 11:00
  3. Save Icon in a file
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2009, 18:07
  4. How to save an image (png) into a xml file
    By richardander in forum Qt Programming
    Replies: 8
    Last Post: 9th October 2009, 09:57
  5. Save qpixmap to file
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 17:36

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.