Finally I found a way to decode that string without home-brewed code.
{
if(line.indexOf("\033") == -1)
XTextProperty tp;
tp.value = const_cast<unsigned char *>((unsigned char const *)line.data());
tp.
encoding = XInternAtom
(QX11Info::display(),
"COMPOUND_TEXT",
true);
tp.format = 8;
tp.nitems = line.length();
char **retList;
int retListLength = -1;
int ret
= Xutf8TextPropertyToTextList
(QX11Info::display(),
&tp,
&retList,
&retListLength
);
if(ret == Success && retListLength == 1) {
free(*retList);
return s;
}
… some more code if there are multiple lines …
QString Reader::toString(QByteArray const &line)
{
if(line.indexOf("\033") == -1)
return QString(line);
XTextProperty tp;
tp.value = const_cast<unsigned char *>((unsigned char const *)line.data());
tp.encoding = XInternAtom(QX11Info::display(), "COMPOUND_TEXT", true);
tp.format = 8;
tp.nitems = line.length();
char **retList;
int retListLength = -1;
int ret = Xutf8TextPropertyToTextList(QX11Info::display(), &tp, &retList, &retListLength);
if(ret == Success && retListLength == 1) {
QString s = QString::fromUtf8(*retList);
free(*retList);
return s;
}
… some more code if there are multiple lines …
To copy to clipboard, switch view to plain text mode
Bookmarks