如何使用QT5(QtQuick 2.1)及以上的窗口上打印度的符号 [英] How to print degree symbol on the window using qt5(QtQuick 2.1) and above

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

问题描述

当我使用最多qt4.8(Qt Quick的1.1)的图形用户界面,然后我能够成功与打印度\\ 260 但是当事情已升级为QT5以上那么这个停止工作。我在网上搜索,发现了很多相关链接,如( http://www.fileformat.info/info/uni$c$c/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,
这说明正在做什么。

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

首先,我存储打印语句字符串文本
作为CPP功能: -

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

                 sprintf(text, "%02d\260  %03d\260 ",latD, longD);

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

,然后用 positionText 在QML文件显示窗口。

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?

感谢。

推荐答案

问题是你用简单的 \\ 260 ANSII C字符串(为const char [] )。在这种情况下,Qt拥有使用一些 codeC 以这种转换以统一code字符。对于当您更改版本的Qt默认codeC某种原因被改变,这就是为什么它停止工作。

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-字符串,它是codeC依赖(这通常会导致这样那样的问题)。您可以定义QChar则常量为 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.

如果你给再presentative例如使用字符串度字符这将是最好的,那么有人会为您提供最佳的解决方案。

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


修改

我会改变你的code是这样的:

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天全站免登陆