Originally Posted by
sandor
Well, hmm, it does not quite work. Actually the problem is not how to put into QString, it is the easy part.
I don't think you understand the problem.
The problem is how to actually print.
The question is very simple:
// ????: printf("%s\n", s);
// ????: printf("%s\n", s.toAscii());
// ????: etc.
// What to put there instead of printf?
QString s = "őű";
// ????: printf("%s\n", s);
// ????: printf("%s\n", s.toAscii());
// ????: etc.
// What to put there instead of printf?
To copy to clipboard, switch view to plain text mode
Well, printf() will work, and so will std::cout, QTextStream and qDebug but you'll will only see the characters you expect if they get into the QString correctly in the first place.
#include <QtCore>
#include <QDebug>
#include <iostream>
printf("%s\n", s.toUtf8().data());
std::cout << s.toUtf8().data() << std::endl;
out << s << endl;
qDebug() << s;
qDebug() << "-----";
}
int main(int argc, char **argv)
{
QString s
("áéőűÃÉÅÅ°");
// mangled by toAscii() output(s);
s = "áéőűÃÉÅÅ°"; // mangled by toAscii() too
output(s);
s
= QString::fromUtf8("áéőűÃÉÅÅ°");
// not mangled output(s);
return 0;
}
#include <QtCore>
#include <QDebug>
#include <iostream>
void output(const QString &s) {
printf("%s\n", s.toUtf8().data());
std::cout << s.toUtf8().data() << std::endl;
QTextStream out(stdout);
out << s << endl;
qDebug() << s;
qDebug() << "-----";
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QString s("áéőűÃÉÅÅ°"); // mangled by toAscii()
output(s);
s = "áéőűÃÉÅÅ°"; // mangled by toAscii() too
output(s);
s = QString::fromUtf8("áéőűÃÉÅÅ°"); // not mangled
output(s);
return 0;
}
To copy to clipboard, switch view to plain text mode
Just for reference I am using Konsole with UTF8 encoding and suitable fonts. This is the output:
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
"áéÅűÃÃÅÅ°"
-----
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
"áéÅűÃÃÅÅ°"
-----
áéőűÃÉÅÅ°
áéőűÃÉÅÅ°
áéőűÃÉÅÅ°
"áéőűÃÉÅÅ°"
-----
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
"áéÅűÃÃÅÅ°"
-----
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
áéÅűÃÃÅÅ°
"áéÅűÃÃÅÅ°"
-----
áéőűÃÉÅÅ°
áéőűÃÉÅÅ°
áéőűÃÉÅÅ°
"áéőűÃÉÅÅ°"
-----
To copy to clipboard, switch view to plain text mode
Bookmarks