How to locate where the qt asserts happens
-
Hi.
I get this output from my application. Many times.
QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0
How do I find out where in the code, this happens. I use QFont::setPointSizeF but comment those calls out, then I still get it.
-
Hi.
I get this output from my application. Many times.
QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0
How do I find out where in the code, this happens. I use QFont::setPointSizeF but comment those calls out, then I still get it.
@Jakob-Clausen
I believe the message will come through standard Qt message handling. See QtMessageHandler qInstallMessageHandler(QtMessageHandler handler). Install your own message handler, run under debugger, put a breakpoint into that function. Look at the stack trace pane in the debugger when that message arrives. -
Wow. That actually worked.
I have a breakpoint where the output arrives at the messagehandler. But it looks like it is happening in the QLabel::paintEvent. But that cannot be right? I have a widget that is derived from QLabel with a custom paintEvent, which calls the QLabel::paintEvent.
My stack trace looks like this.1 QMessageLogger::warning(const char *, ...) const *plt 0x7ffff7042710 2 QFont::setPointSizeF(double) 0x7ffff7121d0a 3 ?? 0x7ffff71d0f40 4 QCss::ValueExtractor::extractFont(QFont *, int *) 0x7ffff71d2714 5 QCss::ValueExtractor::extractFont() 0x7ffff71d28f3 6 QCss::ValueExtractor::extractBox(int *, int *, int *) 0x7ffff71dca29 7 ?? 0x7ffff719583c 8 ?? 0x7ffff71968c3 9 ?? 0x7ffff7196b18 10 ?? 0x7ffff719890e 11 ?? 0x7ffff71990e8 12 ?? 0x7ffff71b9dae 13 QTextDocument::setHtml(QString const&) 0x7ffff717c863 14 ?? 0x7ffff7932c75 15 ?? 0x7ffff7932d85 16 ?? 0x7ffff7934580 17 QLabel::paintEvent(QPaintEvent *) 0x7ffff7934bc0 18 Widget::paintEvent Widget.cpp 195 0x5555555d979f 19 QWidget::event(QEvent *) 0x7ffff7823cb4 20 QFrame::event(QEvent *) 0x7ffff792e756 ... <More>
-
Wow. That actually worked.
I have a breakpoint where the output arrives at the messagehandler. But it looks like it is happening in the QLabel::paintEvent. But that cannot be right? I have a widget that is derived from QLabel with a custom paintEvent, which calls the QLabel::paintEvent.
My stack trace looks like this.1 QMessageLogger::warning(const char *, ...) const *plt 0x7ffff7042710 2 QFont::setPointSizeF(double) 0x7ffff7121d0a 3 ?? 0x7ffff71d0f40 4 QCss::ValueExtractor::extractFont(QFont *, int *) 0x7ffff71d2714 5 QCss::ValueExtractor::extractFont() 0x7ffff71d28f3 6 QCss::ValueExtractor::extractBox(int *, int *, int *) 0x7ffff71dca29 7 ?? 0x7ffff719583c 8 ?? 0x7ffff71968c3 9 ?? 0x7ffff7196b18 10 ?? 0x7ffff719890e 11 ?? 0x7ffff71990e8 12 ?? 0x7ffff71b9dae 13 QTextDocument::setHtml(QString const&) 0x7ffff717c863 14 ?? 0x7ffff7932c75 15 ?? 0x7ffff7932d85 16 ?? 0x7ffff7934580 17 QLabel::paintEvent(QPaintEvent *) 0x7ffff7934bc0 18 Widget::paintEvent Widget.cpp 195 0x5555555d979f 19 QWidget::event(QEvent *) 0x7ffff7823cb4 20 QFrame::event(QEvent *) 0x7ffff792e756 ... <More>
@Jakob-Clausen said in How to locate where the qt asserts happens:
13 QTextDocument::setHtml(QString const&)
When you are stopped on the breakpoint in the debugger, click on this line to make it "the current frame". With luck you can then use the Watch or Expression panes to view what is in the
QString
parameter. Does it contain some request for a particular font, or "size 0", or similar? -
No such luck.
As you can see here, most of the trace is grayed out, so I cannot select it.
When I singlestep through the code the first part, that I recognize as my own is the re implementation of QLabel::paintEvent. Could it be that it calls setPointSizeF, with an argument, that comes from somewhere else?
-
No such luck.
As you can see here, most of the trace is grayed out, so I cannot select it.
When I singlestep through the code the first part, that I recognize as my own is the re implementation of QLabel::paintEvent. Could it be that it calls setPointSizeF, with an argument, that comes from somewhere else?
@Jakob-Clausen
Yes,QLabel
painting will doubtless set a font.
From the error message, verify what the font size is on thatQLabel
?
You might as well comment out theshape...
code or this whole override, the error presumably still occurs without it? -
I have tried with this
void Widget::paintEvent(QPaintEvent* event) { QFontInfo info = fontInfo(); qDebug() << name << info.pixelSize() << info.pointSizeF(); //shape.paintSquare(); QLabel::paintEvent(event); }
And I never get a pixelsize that is zero or negative.
-
I have tried with this
void Widget::paintEvent(QPaintEvent* event) { QFontInfo info = fontInfo(); qDebug() << name << info.pixelSize() << info.pointSizeF(); //shape.paintSquare(); QLabel::paintEvent(event); }
And I never get a pixelsize that is zero or negative.
@Jakob-Clausen
Looking through the stack trace I think you will find theQFont::setPointSizeF(double)
is being called internally by Qt from source line https://codebrowser.dev/qt5/qtbase/src/gui/text/qcssparser.cpp.html#1143.This means it is being called from a CSS/QSS stylesheet string, looking like
<number>pt
and, for whatever reason, that string's<number>
is<= 0
.- Comment out all your own stylesheet directives wherever they are. Does that solve?
- Check the string being passed into
setHtml(QString const&)
. Does that have something like this, to do with a font size, in the HTML?
-
@Jakob-Clausen
Looking through the stack trace I think you will find theQFont::setPointSizeF(double)
is being called internally by Qt from source line https://codebrowser.dev/qt5/qtbase/src/gui/text/qcssparser.cpp.html#1143.This means it is being called from a CSS/QSS stylesheet string, looking like
<number>pt
and, for whatever reason, that string's<number>
is<= 0
.- Comment out all your own stylesheet directives wherever they are. Does that solve?
- Check the string being passed into
setHtml(QString const&)
. Does that have something like this, to do with a font size, in the HTML?
@JonB
Hi again.
I think I have found the error. :-)
First I tried to comment out all my own stylesheet directives by commenting out all calls to setStyleSheet(). That did not work, the error was still there.
Then I looked at your second advise - try to look at the string passed to setHtml(). This was not possible through the stacktrace - it was grayed out, so I could not select it. Maybe I could put a breakpoint in it anyway?
But it turns out that I use html. I have the function richtext that returns a string, that I use in setText(). And richtext does set a fontsize in a html tag. So the solution is to only append the fontsize line, if the fontsize is larger than zero.
Does all this make sense?QString Widget::richtext(QString data, int fontsize, QColor color) { QString text = TAG_BEGIN_START; text += TAG_FONT_SIZE + QString::number(fontsize) + "pt;"; text += TAG_FONT_WEIGHT + QString::number(FONT_WEIGHT) + ";"; text += TAG_FONT_COLOR + color.name() + ";"; text += TAG_END_START; text += data; text += TAG_STOP; return text; }
Thank you very much for your time and help. :-)
-
@JonB
Hi again.
I think I have found the error. :-)
First I tried to comment out all my own stylesheet directives by commenting out all calls to setStyleSheet(). That did not work, the error was still there.
Then I looked at your second advise - try to look at the string passed to setHtml(). This was not possible through the stacktrace - it was grayed out, so I could not select it. Maybe I could put a breakpoint in it anyway?
But it turns out that I use html. I have the function richtext that returns a string, that I use in setText(). And richtext does set a fontsize in a html tag. So the solution is to only append the fontsize line, if the fontsize is larger than zero.
Does all this make sense?QString Widget::richtext(QString data, int fontsize, QColor color) { QString text = TAG_BEGIN_START; text += TAG_FONT_SIZE + QString::number(fontsize) + "pt;"; text += TAG_FONT_WEIGHT + QString::number(FONT_WEIGHT) + ";"; text += TAG_FONT_COLOR + color.name() + ";"; text += TAG_END_START; text += data; text += TAG_STOP; return text; }
Thank you very much for your time and help. :-)
@Jakob-Clausen said in How to locate where the qt asserts happens:
QString::number(fontsize)`
Indeed you need to check
fontsize > 0
here. If that is not true it would lead to your error. -
@Jakob-Clausen said in How to locate where the qt asserts happens:
QString::number(fontsize)`
Indeed you need to check
fontsize > 0
here. If that is not true it would lead to your error.@JonB Exactly.
Thank you very much. :-)