如何使用 qt5(QtQuick 2.1) 及更高版本在窗口上打印度数符号 [英] How to print degree symbol on the window using qt5(QtQuick 2.1) and above

查看:24
本文介绍了如何使用 qt5(QtQuick 2.1) 及更高版本在窗口上打印度数符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为 gui 使用高达 qt4.8(qt quick 1.1) 时,我可以成功地使用 260 打印学位,但是当升级到 qt5 及更高版本时,它就停止了工作.我在网上搜索并找到了许多相关链接,例如 (http://www.fileformat.info/info/unicode/char/00b0/index.htm)我试过但没有帮助.我是否需要包含一些用于 usinf UTF 格式的库,否则问题是其他的.请有人帮忙.怎么办?

When I was using up to qt4.8(qt quick 1.1) for gui then I am successfully able to print degree with 260 but when things got upgraded to qt5 and above then this stopped working. I searched on the net and found many relevant link such as (http://www.fileformat.info/info/unicode/char/00b0/index.htm) I tried but no help. Do I need to include some library for usinf UTF format or problem is sth else. Please some one help. What to do?

@已修改,这里描述了正在做的事情.

@Revised, Here it is described what is being done.

首先,我将可打印语句存储在字符串 text 中.如在 cpp 函数中:-

First I am storing the printable statement in string text. As in cpp function:-

                 sprintf(text, "%02d260  %03d260 ",latD, longD);

                 QString positionText(text.c_str());
                 return positionText;     

然后使用qml文件中的positionText显示在窗口上.

And then using positionText in qml file to display on the window.

那么,有人请回答我需要做什么才能获得展示学位?

So, someone please answer what do I need to do to have degree in display?

谢谢.

推荐答案

问题很简单,你在 Ansii C-string (const char [] 中使用了 260).在这种情况下,Qt 使用了一些 codec 将其转换为 Unicode人物.由于某种原因,当您更改 Qt 版本时,默认编解码器已更改,这就是它停止工作的原因.

Problem is simple you used 260 most probably inside Ansii C-string (const char []). In such cases Qt has use some codec to convert this to Unicode characters. For some reason when you change Qt version default codec was changed and this is why it stopped working.

无论如何,您的方法是错误的.您不应该使用依赖于编解码器的 C 字符串(通常这会导致此类问题).您可以将 QChar const 定义为 QChar(0260) 或最好的方法是使用 tr 并提供翻译.

Anyway your approach is wrong. You shouldn't use C-string which are codec depended (usually this leads to this kind of problems). You can define QChar const as QChar(0260) or best approach is to use tr and provide translation.

如果你给出带有度字符的字符串的代表性例子,那么有人会为你提供最好的解决方案.

It would be best if you give representative example with string with degree character, then someone will provide you best solution.


我会像这样更改您的代码:

I would change your code like this:

const QChar degreeChar(0260); // octal value
return QString("%1%3  %2%3").arg(latD, 2, 10, '0').arg(longD, 3, 10, '0').arg(degreeChar);

或添加将处理此行的翻译:

or add translation which will handle this line:

return tr("%1degree  %2degree").arg(latD, 2, 10, '0').arg(longD, 3, 10, '0');

请注意,无论当前语言环境如何,都只需要添加此行的翻译.

Note that this translation for this line only have to be added always no mater what is current locale.

这篇关于如何使用 qt5(QtQuick 2.1) 及更高版本在窗口上打印度数符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆