PDA

View Full Version : Qt is crashing when showing this tooltip. Why?



kalos80
26th July 2010, 10:23
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:



QFile file("tooltip.txt");
file.open(QIODevice::ReadOnly);
QTextStream stream(&file);
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++
.....

SixDegrees
26th July 2010, 11:20
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?

borisbn
26th July 2010, 11:52
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

kalos80
26th July 2010, 12:07
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.

borisbn
26th July 2010, 12:58
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.

squidge
26th July 2010, 14:02
Please create a minimum compilable application that demonstrates the problem. If the error still occurs, then post that application.

kalos80
26th July 2010, 14:23
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 (http://bugreports.qt.nokia.com/browse/QTBUG-12403) for this problem.

I would be really glad if I could find a workaround to this problem

kalos80
26th July 2010, 15:45
Well I tested the application against the following styles:

Windows
WindowsXP
Motif
CDE
Plastique
Cleanlooks

It crashes only with WindowsXP and Cleanlooks styles

borisbn
26th July 2010, 15:45
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 :)

Lykurg
26th July 2010, 15:57
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.

saa7_go
26th July 2010, 16:35
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[])
{
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;
}


Then i modify my code to this


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;
}

It works fine but the text missing some spaces and newlines.
BTW, i use qt-sdk-win-opensource-2010.03.

kalos80
26th July 2010, 17:00
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

saa7_go
26th July 2010, 17:10
Maybe adding the following code will fix your problems



tooltipText.prepend("<pre>");
tooltipText.append("</pre>");

myWidget->setToolTip(tooltipText);


The text formatting is ok, but not the font.

kalos80
26th July 2010, 17:23
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.

Lykurg
26th July 2010, 17:51
Have you tried with an other (simple) text file? Because it might be that in the text file something went wrong with the encoding.

norobro
26th July 2010, 18:46
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.

kalos80
27th July 2010, 11:05
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 (http://bugreports.qt.nokia.com/browse/QTBUG-12403), clearly mentioning you.