0

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.

jestin
  • 15
  • 3

1 Answers1

0

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) + "");
  • Thanks Roku. Adding an empty string makes it work even with Qt 4.7.4 and 4.8.4. It would be great if somebody could explain how this solves the problem. Is it a bug? – jestin Apr 21 '13 at 08:43