degree Celsius symbol not displayed in Qt QML
-
I am using sqlite DB to store records
In DB "High Temperature Alarm Setting Changed to %1°C++3" text stored in Table.I read record from DB in c++ class as follows:
SqlQuery query; query.prepare("SELECT * FROM Events ORDER BY id DESC LIMIT 50 "); query.exec(); QString msg while(query.next()){ QString msg=query.value(3).toString(); qDebug()<<"msg="<<msg; QStringList array = string.split("+"); QString sign=array[2].toInt()>0?"+":"-"; QString trString = tr(QString(array[0]).replace("%1",sign+array[2]).toLocal8Bit()); qDebug()<<"trString="<<trString; }
// Output: "High Temperature Alarm Setting Changed to %1?C++3"
// expected: "High Temperature Alarm Setting Changed to %1°C++3"In ubuntu 18, it works fine & displaying degree celsius symbol but in G&F Display device it shows "?" symbol intead of "°"
Device we are using following device
https://support.garz-fricke.com/projects/Santino/Linux-Yocto/Releases/yocto-jethro-santino-overview.htmQt version: 5.9.4
-
@JKSH said in degree Celsius symbol not displayed in Qt QML:
toLocal8Bit
Code is working correctly with toLocal8Bit() on another device with same bsp & h/w. Only one change is on my device I had updated bsp version & then downgrade it (for testing purpose) , In this process some lib/config may be not reset/remove correctly due to this representation problem comes.
Now I have change toLocal8Bit() to toUtf8() and now it works on both devices.
tr(QString(array[0]).replace("%1",sign+array[2]).toUtf8());
Thanks to all for help
-
Make sure your font has the degree symbol in it.
-
I am using sqlite DB to store records
In DB "High Temperature Alarm Setting Changed to %1°C++3" text stored in Table.I read record from DB in c++ class as follows:
SqlQuery query; query.prepare("SELECT * FROM Events ORDER BY id DESC LIMIT 50 "); query.exec(); QString msg while(query.next()){ QString msg=query.value(3).toString(); qDebug()<<"msg="<<msg; QStringList array = string.split("+"); QString sign=array[2].toInt()>0?"+":"-"; QString trString = tr(QString(array[0]).replace("%1",sign+array[2]).toLocal8Bit()); qDebug()<<"trString="<<trString; }
// Output: "High Temperature Alarm Setting Changed to %1?C++3"
// expected: "High Temperature Alarm Setting Changed to %1°C++3"In ubuntu 18, it works fine & displaying degree celsius symbol but in G&F Display device it shows "?" symbol intead of "°"
Device we are using following device
https://support.garz-fricke.com/projects/Santino/Linux-Yocto/Releases/yocto-jethro-santino-overview.htmQt version: 5.9.4
@Vijay-R-Gawade What is the purpose of calling
toLocal8Bit()
? -
Use \302\260
QString str_degree( "20\302\260C" );
std::cout << " == " << qPrintable( str_degree ) << std::endl; -
@JoeCFD said in degree Celsius symbol not displayed in Qt QML:
std::cout << " == " << qPrintable( str_degree ) << std::endl;
I do not understand the problem:
- Is it the log message output?
- the output in QML?
- the reading from SQL?
@KroMignon I load temperature with unit C from xml and add \302\260 to it when it is displayed.
My code above is only for testing, -
@JKSH said in degree Celsius symbol not displayed in Qt QML:
toLocal8Bit
Code is working correctly with toLocal8Bit() on another device with same bsp & h/w. Only one change is on my device I had updated bsp version & then downgrade it (for testing purpose) , In this process some lib/config may be not reset/remove correctly due to this representation problem comes.
Now I have change toLocal8Bit() to toUtf8() and now it works on both devices.
tr(QString(array[0]).replace("%1",sign+array[2]).toUtf8());
Thanks to all for help