Results 1 to 5 of 5

Thread: problem with accents

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default problem with accents

    Hi,

    I have a file with encoding with UTF-8 Unicode text.

    I read from file to insert the fields file in a qtablewidget. For do this I do:

    QTextStream ins(&file);

    while (!ins.atEnd()) {
    QString line = ins.readLine();
    QTableWidgetItem *item = new QTableWidgetItem;
    item->setText(line);
    tabla->setItem(b,0,item);
    tabla->setRowHeight(b,20);
    b++;
    }

    Everything it's ok and the qtablewidget shows me the fields with accents.
    But then I try to assign a variable to a cell selected with:

    titulo= tabla->item(rowd,cold)->text();

    And I see that this variable have strange characters instead of accents.
    How could I solved that?

    Many thanks and sorry for my english!

  2. #2
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 7 Times in 6 Posts

    Default Re: problem with accents

    Hi,

    I've a similar problem with QSqlQueryModel, and you can try this:


    while (!ins.atEnd()) {
    QString line = ins.readLine();

    QString lineUTF8 = QString::fromUtf8(line.toByteArray());

    QTableWidgetItem *item = new QTableWidgetItem;
    item->setText(lineUTF8);
    tabla->setItem(b,0,item);
    tabla->setRowHeight(b,20);
    b++;
    }

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: problem with accents

    Quote Originally Posted by vcp View Post
    Hi,

    I've a similar problem with QSqlQueryModel, and you can try this:


    while (!ins.atEnd()) {
    QString line = ins.readLine();

    QString lineUTF8 = QString::fromUtf8(line.toByteArray());

    QTableWidgetItem *item = new QTableWidgetItem;
    item->setText(lineUTF8);
    tabla->setItem(b,0,item);
    tabla->setRowHeight(b,20);
    b++;
    }
    It doesn't works it says me:

    cpp400 : error: ‘class QString’ doen't have any member called ‘toByteArray’

    Any help?
    Many thanks!

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

    Default Re: problem with accents

    You must set correct code for stream. Default codec is system locale dependent. So :
    Qt Code:
    1. QTextStream ins(&file);
    2. ins.setCodec("UTF-8");
    3.  
    4. while (!ins.atEnd()) {
    5. QString line = ins.readLine();
    6. item->setText(line);
    7. tabla->setItem(b,0,item);
    8. tabla->setRowHeight(b,20);
    9. b++;
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: problem with accents

    Many thanks!
    There is no problem, the program runs ok. The problem is now that when I read from standard output of a process and put the text in a qtextbrowser, the text have strange characters instead of accents.

    I do:

    Qt Code:
    1. QByteArray result=cron->readAllStandardOutput();
    2. QStringList lines = QString(result).split("\n");
    3.  
    4. foreach (QString line, lines) {
    5.  
    6. QMessageBox::information(this, "columna",line);
    7. texto->append(line);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Any help?
    Many thanks!

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 10:05
  2. Replies: 19
    Last Post: 4th April 2009, 00:17
  3. Problem with windows and accents
    By esterbonmati in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2009, 11:00
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22: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
  •  
Qt is a trademark of The Qt Company.