Results 1 to 5 of 5

Thread: Non-standard ascii characters to and from a file

  1. #1
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Non-standard ascii characters to and from a file

    Hello everyone!

    I'm developing a small app witch contains a list view and then saves it to the disk and loads it back.
    Everything works just fine, until I put non-standard ASCII chars into the list, like Å¡čžćđ.
    If I go ahead and just save that string like it is, i get ?(question marks) all over instead of the inputed chars.
    If I change the string wiht QString::local8Bit() function then it saves right.
    The problem is, when I try to load the file back. The chars load good into a QString. So if in a file there is Å¡čćžđ then there's going to be the same in the QString to witch I load it.
    The problem is when I add this QString to the list view. Then I get these chars:
    ščƾ
    Now I've ran out of ideas, and don't know what could I do next.
    This is how I add it to the list view:
    Qt Code:
    1. {
    2. QString Num;
    3. QPixmap icon;
    4.  
    5. icon = setItemIcon(Tip, Lastnistvo);
    6.  
    7. QListViewItem * item = new QListViewItem( listView1, 0 );
    8. if ( zap_st == -1 )
    9. item->setText( 0, Num.setNum( itemCount ) );
    10. else
    11. item->setText( 0, Num.setNum( zap_st ) );
    12. item->setText( 1, Naslov );
    13. item->setPixmap( 1, icon );
    14. dataChange = 1;
    15.  
    16. StatusBar->message( tr( "\"%1\" added to list").arg(Naslov), 2000 );
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Non-standard ascii characters to and from a file

    How do you read those strings from the file?

  3. #3
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Non-standard ascii characters to and from a file

    QFile f( fileName );
    f.readLine(QString, int length)

  4. #4
    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: Non-standard ascii characters to and from a file

    Use QTextStream instead. This way you can enforce the encoding using QTextStream::setEncoding() or QTextStream::setCodec().

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

    Tux-Slack (10th July 2007)

  6. #5
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Non-standard ascii characters to and from a file

    Thank you very much for this.

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.