2016-03-31 62 views
1

我有一個Unicode問題。德國字母äüöß僅在黑色菱形中顯示爲白色問號。我在Qt5.5.1中創建了一個QAbstractTableModelQAbstractTableModel和Unicode(德語變音符號)

我的文檔是UTF-8編碼的。我已經嘗試過了,但我仍然遇到同樣的問題。

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("ä"); 
    // 
} 

有沒有人有關於如何正確顯示這些字符的線索?

編輯:是的,我需要一個字符串,我只是在這個例子中使用了一個字符。

並感謝阿德里亞諾Repetti,這是解決方案:

QString::fromWCharArray(L"Steißbein") 
+0

你需要出示單個字符? – vahancho

+1

它不是一個UTF-8字符串,簡單的方法是返回QString :: fromWCharArray(L「ä」)'。如果你真的有一個字符(你不需要處理e +的東西),你可以使用'QChar',但我更喜歡一般形式。 –

回答

0

如果需要返回單個字符,我建議做以下幾點:

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); 
[..] 
相關問題