Results 1 to 4 of 4

Thread: Please help with codec in QSettings

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Please help with codec in QSettings

    Hi,

    I try to create an ini file using QSettings with utf8 codec, but I can' get key right regardless what I do. Please advise where I do wrong.

    Thanks.

    Qt Code:
    1. #include <QApplication>
    2. #include <QSettings>
    3. #include <QTextCodec>
    4. #include <QDebug>
    5.  
    6. int main( int argc, char** argv )
    7. {
    8. QApplication app( argc, argv );
    9.  
    10. QTextCodec::setCodecForLocale( QTextCodec::codecForName( "utf8" ) );
    11.  
    12. QSettings settings( "Test.ini", QSettings::IniFormat );
    13. settings.setIniCodec( QTextCodec::codecForName( "utf8" ) );
    14.  
    15. settings.beginGroup( "LITH_SEC" );
    16.  
    17. settings.setValue( QString::fromUtf8( "介壳灰岩" ), QString::fromUtf8( "灰岩" ) );
    18. settings.setValue( QString::fromLocal8Bit( "介壳灰岩" ), QString::fromLocal8Bit( "灰岩" ) );
    19. settings.setValue( "介壳灰岩", "灰岩" );
    20. settings.setValue( QString( "介壳灰岩" ).toUtf8(), QString( "灰岩" ).toUtf8() );
    21. settings.setValue( QString( "介壳灰岩" ).toLocal8Bit(), QString( "灰岩" ).toLocal8Bit() );
    22.  
    23. settings.endGroup();
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    It produces the following file:

    [LITH_SEC]
    %U4ECB%U58F3%U7070%U5CA9=灰岩
    %E4%BB%8B%E5%A3%B3%E7%81%B0%E5%B2%A9=ç<81>° ¥Â²Â©
    %C3%A4%C2%BB%C2%8B%C3%A5%C2%A3%C2%B3%C3%A7%C2%81%C 2%B0%C3%A5%C2%B2%C2%A9=@ByteArray(çÂ<81 >°å²©)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Please help with codec in QSettings

    What seems to be the problem? What did you expect to see in the output?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Please help with codec in QSettings

    I want to see the ini file to be:

    [LITH)SEC]
    介壳灰岩=灰岩

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Please help with codec in QSettings

    This ain't gonna happen, keys apparently need to have ASCII values only thus everything non-ASCII will be percentage encoded. If you really need that, you will have to provide your own backend for QSettings.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QSettings Codec Problem
    By yaseminyilmaz in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2012, 15:00
  2. PyQt H265 Codec
    By blanchoir in forum Newbie
    Replies: 0
    Last Post: 3rd August 2011, 22:01
  3. Qt phonon and Codec
    By alexcuiCN in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2010, 08:56
  4. Retrieve string codec
    By Raccoon29 in forum Newbie
    Replies: 3
    Last Post: 26th January 2009, 21:21
  5. Using setCodecForCStrings(codec) in Constructor
    By danbetz in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2007, 21:23

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.