1

I have a Unicode problem. The German Letters ä, ü, ö and ß are only visible as a white question mark in a black rhombus. I've made a QAbstractTableModel in Qt5.5.1.

My document is UTF-8 coded. I already tried this, but I still get the same problem.

QVariant bodyPartModel::data(const QModelIndex &index, int role) const
{
    switch (role){
        case Qt::DisplayRole:
            if (col == 0 && row == 0) return tr("ü");    
            if (col == 0 && row == 2) return String::fromUtf8("ä");
    //
}

Does anyone have a clue as to how to display these characters correctly?

edit.: Yes i need a String, i just used one char in this example.

And Thanks to Adriano Repetti, this was the Solution:

QString::fromWCharArray(L"Steißbein")
  • Do you need to show a single character? – vahancho Mar 31 '16 at 07:41
  • 1
    It's not an UTF-8 string, easy way is `return QString::fromWCharArray(L"ä")`. You _may_ use single `QChar` if you really have a single character (and you won't need to handle e + ' stuff) but I prefer the general form. – Adriano Repetti Mar 31 '16 at 08:07

1 Answers1

0

If you need to return a single character, I would suggest doing the following:

QVariant bodyPartModel::data(const QModelIndex &index, int role) const
{
    switch (role){
    case Qt::DisplayRole:
        if (col == 0 && row == 0) return QChar(0x00FC);    
        if (col == 0 && row == 2) return QChar(0x00E4);
[..]
vahancho
  • 20,808
  • 3
  • 47
  • 55