2 Attachment(s)
Qt is crashing when showing this tooltip. Why?
My Qt application keeps on crashing when the tooltip in the attached file is shown.
To reproduce the problem just set a widget tooltip in the following way:
Code:
QFile file("tooltip.txt");
QString tooltipText
= stream.
readAll();
file.close();
myWidget->setToolTip(tooltipText);
I'm using the latest version of Qt (4.6.3) on Windows
I'm going to submit a bugreport, but in the meanwhile can anyone suggest me a solution to fix this crash problem?
Thanks in advance for your help
Update:
I attached a simple project to reproduce the problem.
I compile that project with Qt 4.6.3 and Visual Studio 2008 Express on Windows Xp
In debug mode it crashes always when I move the mouse on top of the widget and the tooltip is shown. In relase mode sometimes it crashes sometimes not.
Here is part of the call stack when it crashes:
tGuid4.dll!`anonymous namespace'::LineBreakHelper::currentGlyph() Line 1683 + 0x1a bytes C++
QtGuid4.dll!`anonymous namespace'::LineBreakHelper::adjustRightBearing() Line 1692 + 0xe bytes C++
QtGuid4.dll!QTextLine::layout_helper(int maxGlyphs=2147483647) Line 1931 C++
QtGuid4.dll!QTextLine::setLineWidth(double width=8388607.0000000000) Line 1602 C++
QtGuid4.dll!qt_format_text(const QFont & fnt={...}, const QRectF & _r={...}, int tf=134218769, const QTextOption * option=0x00000000, const QString & str={...}, QRectF * brect=0x00000000, int tabstops=48, int * __formal=0x00000000, int tabarraylen=0, QPainter * painter=0x0012cb54) Line 7747 C++
QtGuid4.dll!QPainter::drawText(const QRect & r={...}, int flags=1041, const QString & str={...}, QRect * br=0x00000000) Line 5807 + 0x41 bytes C++
QtGuid4.dll!QStyle::drawItemText(QPainter * painter=0x0012cb54, const QRect & rect={...}, int alignment=1041, const QPalette & pal={...}, bool enabled=true, const QString & text={...}, QPalette::ColorRole textRole=ToolTipText) Line 541 C++
QtGuid4.dll!QLabel::paintEvent(QPaintEvent * __formal=0x0012d3f0) Line 1038 C++
QtGuid4.dll!QTipLabel::paintEvent(QPaintEvent * ev=0x0012d3f0) Line 230 C++
QtGuid4.dll!QWidget::event(QEvent * event=0x0012d3f0) Line 8191 C++
.....
Re: Qt is crashing when showing this tooltip. Why?
Have you checked the stream to see if the file is being read without error? Have you tried printing out the resulting string to see if it is what you expect?
Re: Qt is crashing when showing this tooltip. Why?
Ok, I was try this example and I didn't have any problem. If my program see this file, then I can see a contents of this file as a tooltip. If my program doesn't see this file, then I see nothing as a tooltip.
I have: MSVC 2008, Qt 4.6.2, Windows 7
Re: Qt is crashing when showing this tooltip. Why?
This is just an example to reproduce the problem.
In my application the error string is not read from a file. It is the result of the execution of some operations.
I just saved that string in a file and then created a test application to reproduce the problem.
Re: Qt is crashing when showing this tooltip. Why?
I think, that problem is not in a setToolTip function. Maybe your other code brings this error. If you try a simplest application, that just set a toolTip to a widget, you'll see, that it's true.
Re: Qt is crashing when showing this tooltip. Why?
Please create a minimum compilable application that demonstrates the problem. If the error still occurs, then post that application.
Re: Qt is crashing when showing this tooltip. Why?
I just updated the main post adding a very simple test project reproducing the problem.
Please give it a try, the project is very simple, just create a widget and sets its tooltip to the guilty one.
I compile that project with latest Qt version 4.6.3 on Windows Xp and Visual Studio 2008 Express Edition
I submitted a bugreport for this problem.
I would be really glad if I could find a workaround to this problem
Re: Qt is crashing when showing this tooltip. Why?
Well I tested the application against the following styles:
Windows
WindowsXP
Motif
CDE
Plastique
Cleanlooks
It crashes only with WindowsXP and Cleanlooks styles
Re: Qt is crashing when showing this tooltip. Why?
I downloaded your project, compiled it and ran. When I move the mouse to widget I see a tooltip from file.
Then I ask my colleague, that has Qt 4.6.3, to do the same, and it works OK on his computer. I and my colleague tried both Debug and Release configurations. It works fine. Try to reinstall Qt, Studio and, maybe, Windows :)
Re: Qt is crashing when showing this tooltip. Why?
I also tested it with QCleanlooksStyle and it worked fine. So there is probably something wrong with your environment.
P.s.: You should only send a bug report if you are 99.9999999% that it is not related to any things on your special computer setup. Therefore you should setup a clean environment in a virtual box and test your errors there.
Re: Qt is crashing when showing this tooltip. Why?
I try to show the text from tooltip.txt using QMessageBox, and my application crashes. The error is similar to kalos80.
Code:
int main(int argc, char *argv[])
{
QFile file("tooltip.txt");
return 0;
file.close();
return 0;
}
Then i modify my code to this
Code:
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;
}
It works fine but the text missing some spaces and newlines.
BTW, i use qt-sdk-win-opensource-2010.03.
Re: Qt is crashing when showing this tooltip. Why?
I'm happy that someone else could reproduce the problem. :)
Also if I call simplified() function on the tooltip string, there is no crash, but I lose the original text formatting
Re: Qt is crashing when showing this tooltip. Why?
Maybe adding the following code will fix your problems
Code:
tooltipText.prepend("<pre>");
tooltipText.append("</pre>");
myWidget->setToolTip(tooltipText);
The text formatting is ok, but not the font.
Re: Qt is crashing when showing this tooltip. Why?
saa7_go,
yes your solution seems to work.
I wonder wether this works in all cases or there could still be some tooltips that could cause my application to crash.
I can use it as a temporary solution, waiting for a fix to such bug.
Re: Qt is crashing when showing this tooltip. Why?
Have you tried with an other (simple) text file? Because it might be that in the text file something went wrong with the encoding.
1 Attachment(s)
Re: Qt is crashing when showing this tooltip. Why?
On my machine your app crashes because of consecutive ASCII tab (0x09) and LF (0x0A) characters after "...XYrange,recn,mode)" in tooltip.txt.
Is that combination of control characters significant? I Goolged a bit but didn't find anything.
I even get a crash with the attached simple file.
Re: Qt is crashing when showing this tooltip. Why?
norobro, it seems you found the cause of the crash:
a tab followed by the line feed character.
I will change my code trying to avoid that sequence of characters.
In any case, I still think I can show anything on a tooltip and it should not crash.
I will add your hints to the bugreport, clearly mentioning you.