Finally I found a way to decode that string without home-brewed code.

Qt Code:
  1. QString Reader::toString(QByteArray const &line)
  2. {
  3. if(line.indexOf("\033") == -1)
  4. return QString(line);
  5.  
  6. XTextProperty tp;
  7. tp.value = const_cast<unsigned char *>((unsigned char const *)line.data());
  8. tp.encoding = XInternAtom(QX11Info::display(), "COMPOUND_TEXT", true);
  9. tp.format = 8;
  10. tp.nitems = line.length();
  11.  
  12. char **retList;
  13. int retListLength = -1;
  14. int ret = Xutf8TextPropertyToTextList(QX11Info::display(), &tp, &retList, &retListLength);
  15. if(ret == Success && retListLength == 1) {
  16. QString s = QString::fromUtf8(*retList);
  17. free(*retList);
  18. return s;
  19. }
  20. … some more code if there are multiple lines …
To copy to clipboard, switch view to plain text mode