Hello,
Despite all my research on the web, I'm still failing to display correctly a math expression using the MathML engine of Qwt. So far, I created a minimalist "testing project", aiming to only display a MathML-formatted text fed in via a text file in the execution directory :
// includes erased here for clarity
int main(int argc, char** argv)
{
ifstream ifs("text");
std::string fullText="";
while(!ifs.eof())
{
std::string line;
getline(ifs,line);
fullText += line + "\n";
}
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8"));
// Strings in files are UTF-8 encoded
QString locale
= QLocale::system().
name().
section('_',
0,
0);
// Installs a translator to the user's locale a.installTranslator(&translator);
lbl->setMinimumHeight(100);
lbl->setMinimumWidth(200);
lbl->show();
return a.exec();
}
// includes erased here for clarity
int main(int argc, char** argv)
{
ifstream ifs("text");
std::string fullText="";
while(!ifs.eof())
{
std::string line;
getline(ifs,line);
fullText += line + "\n";
}
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8")); // Strings in files are UTF-8 encoded
QwtText::setTextEngine(QwtText::MathMLText, new QwtMathMLTextEngine()); // Setting Qwt text engine to MathML
QApplication a(argc, argv);
QString locale = QLocale::system().name().section('_', 0, 0); // Installs a translator to the user's locale
QTranslator translator;
translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
a.installTranslator(&translator);
QwtText text(QString(fullText.c_str()), QwtText::MathMLText);
QwtTextLabel* lbl = new QwtTextLabel(text);
lbl->setMinimumHeight(100);
lbl->setMinimumWidth(200);
lbl->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
My "text" file contains a MathML expression directly copy/pasted from Wikipedia, to display the solutions of a quadratic equation, which - I suppose - is syntaxically correct : http://pastebin.com/Nq6gYkvf.
This code results displaying only letters, not formatted at all, as seen in this screenshot :
tmp.png
What am I doing wrong?
Thanks for your help,
Tobast.
Bookmarks