Domanda

I am trying to display some dynamically generated hindi text on a QPushbutton.

Please have a look at the following code:

char nam[] = { 40, 9, 62, 9, 46, 9 };
QString nameStringInHindi(QString::fromRawData((QChar *)nam, 3));
qDebug() << nameStringInHindi;

Output: "नाम"

But if I do ui->pushButton->setText(nameStringInHindi) //some junk characters are getting printed.

I have tried setting up the application font as well.

QFontDatabase::addApplicationFont("/usr/share/fonts/lohit-devanagari/Lohit-Devanagari.ttf")

and QApplication::setFont(QFont("Lohit Devanagari",12));

but it did not help.

Could someone please help me with this issue? Thank you so much for your time.

È stato utile?

Soluzione

I don't know why your code doesn't work, but adding an empty string to the string created from raw data somehow fixes the string. This works in Linux with Qt 5.0.1:

QString nameStringInHindi(QString::fromRawData((QChar*)nam, 3) + "");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top