moc: Fix compilation of text strings containing non-ASCII

On platforms where char is signed, like x86, the following is an error
(narrowing conversion):

 unsigned char x[] = { '\xc3' };

Change-Id: I495bc19409f348069f5bfffd15518f9ef4e43faf
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2018-09-05 10:01:00 -07:00
parent c0e94fa0cd
commit b66357e3eb
4 changed files with 29 additions and 2 deletions

View File

@ -82,8 +82,10 @@ private:
void putChar(char c)
{
putNewline();
if (c < 0x20 || c >= 0x7f)
if (uchar(c) < 0x20)
fprintf(out, " '\\x%x',", uint8_t(c));
else if (uchar(c) >= 0x7f)
fprintf(out, " uchar('\\x%x'),", uint8_t(c));
else if (c == '\'' || c == '\\')
fprintf(out, " '\\%c',", c);
else

View File

@ -35,7 +35,7 @@
class ThePlugin : public QObject, public PluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface" FILE "../empty.json")
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface" FILE "../utf8_data.json")
Q_INTERFACES(PluginInterface)
public:

View File

@ -210,6 +210,14 @@ void tst_QPluginLoader::errorString()
{
QPluginLoader loader( sys_qualifiedLibraryName("theplugin")); //a plugin
// Check metadata
const QJsonObject metaData = loader.metaData();
QCOMPARE(metaData.value("IID").toString(), QStringLiteral("org.qt-project.Qt.autotests.plugininterface"));
const QJsonObject kpluginObject = metaData.value("MetaData").toObject().value("KPlugin").toObject();
QCOMPARE(kpluginObject.value("Name[mr]").toString(), QString::fromUtf8("चौकट भूमिती"));
// Load
QCOMPARE(loader.load(), true);
QCOMPARE(loader.errorString(), unknown);

View File

@ -0,0 +1,17 @@
{
"KPlugin": {
"Name": "WindowGeometry",
"Name[mr]": "चौकट भूमिती",
"Name[pa]": "ਵਿੰਡੋਜੁਮੈਟਰੀ",
"Name[th]": "มิติขนาดของหน้าต่าง",
"Name[uk]": "Розміри вікна",
"Name[zh_CN]": "窗口形状",
"Name[zh_TW]": "視窗位置",
"ServiceTypes": [
"KCModule"
]
},
"X-KDE-ParentComponents": [
"windowgeometry"
]
}