I try to show the text from tooltip.txt using QMessageBox, and my application crashes. The error is similar to kalos80.
int main(int argc, char *argv[])
{
QFile file("tooltip.txt");
return 0;
file.close();
return 0;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file("tooltip.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 0;
QTextStream stream(&file);
QString str = stream.readAll();
file.close();
QMessageBox::warning(0, "INFO", str);
return 0;
}
To copy to clipboard, switch view to plain text mode
Then i modify my code to this
int main(int argc, char *argv[])
{
QFile file("tooltip.txt");
return 0;
qDebug() << str;
file.close();
msgbox.setTextFormat(Qt::RichText); // using Qt::AutoText or Qt::PlainText crashes too!
msgbox.setText(str);
msgbox.exec();
return 0;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file("tooltip.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 0;
QTextStream stream(&file);
QString str = stream.readAll();
qDebug() << str;
file.close();
QMessageBox msgbox;
msgbox.setTextFormat(Qt::RichText); // using Qt::AutoText or Qt::PlainText crashes too!
msgbox.setText(str);
msgbox.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
It works fine but the text missing some spaces and newlines.
BTW, i use qt-sdk-win-opensource-2010.03.
Bookmarks