[SOLVED] Qt messages in console: where do the problems occur?
-
I have quite some messages like the following in my console window:
QLayout: Attempting to add QLayout "" to FooBarWidget "", which already has a layout QGradient::setColorAt: Color position must be specified in the range 0 to 1
The problem is that no file names or line numbers are specified in these messages, and our codebase is too large to search for these problems manually or even have a clue where they occur.
How can I find out where in our code the reported problems occur?
Thanks
Bart -
I have quite some messages like the following in my console window:
QLayout: Attempting to add QLayout "" to FooBarWidget "", which already has a layout QGradient::setColorAt: Color position must be specified in the range 0 to 1
The problem is that no file names or line numbers are specified in these messages, and our codebase is too large to search for these problems manually or even have a clue where they occur.
How can I find out where in our code the reported problems occur?
Thanks
BartHi,
Here are some ideas:
- Insert your own messages around your code and then see whether they occur before or after the internal messages:
qDebug("Hello");
- Run your program through a debugger. Set a breakpoint, and keep stepping through the code until you see the first message.
Anyway, you have a useful clue: Look for functions that call
setLayout()
onFooBarWidget
- Insert your own messages around your code and then see whether they occur before or after the internal messages:
-
Thanks for the suggestions, but I'm afraid these manual search procedures will be too cumbersome, especially if I have to repeat them for all the messages that I get.
As I thought these messages were qWarning()s, i tried defining QT_FATAL_WARNINGS so that I can have backtraces in my debugger, but my program doesn't exit when it encounters such a Qt message.
Something i'm thinking of is setting breakpoints in the Qt code itself, at the place where it writes the "QLayout: Attempting to add QLayout"... I'm just not sure if this is possible. I will try it out right now!
-
@Bart_Vandewoestyne said:
Something i'm thinking of is setting breakpoints in the Qt code itself
That's what I usually do first and it's the fastest way I know.
-
Thanks for the suggestions, but I'm afraid these manual search procedures will be too cumbersome, especially if I have to repeat them for all the messages that I get.
As I thought these messages were qWarning()s, i tried defining QT_FATAL_WARNINGS so that I can have backtraces in my debugger, but my program doesn't exit when it encounters such a Qt message.
Something i'm thinking of is setting breakpoints in the Qt code itself, at the place where it writes the "QLayout: Attempting to add QLayout"... I'm just not sure if this is possible. I will try it out right now!
@Bart_Vandewoestyne said:
Hi I was facing similar problem and I ended up with own debug build of Qt libraries and breakpoints in qWarning() implementation. -
Hi,
That kind of message generally comes from a QMainWindow derived class, so indeed, just check where you create layouts to ensure you either don't construct passing this as parent or call setLayout with it.
-
I have quite some messages like the following in my console window:
QLayout: Attempting to add QLayout "" to FooBarWidget "", which already has a layout QGradient::setColorAt: Color position must be specified in the range 0 to 1
The problem is that no file names or line numbers are specified in these messages, and our codebase is too large to search for these problems manually or even have a clue where they occur.
How can I find out where in our code the reported problems occur?
Thanks
Bart@Bart_Vandewoestyne For the record: I created my own debug build of Qt and put breakpoints in the Qt source code to find the cause of these warnings. This works quite well. Thanks for the suggestions!
-
@Bart_Vandewoestyne, I know the thread is solved but perhaps this can help someone else or yourself in future.
An alternative to what @yeckel said:
I ended up with own debug build of Qt libraries and breakpoints in qWarning()
You can use the qInstallMsgHandler() function to install a hander then add some code like:
if(QString(msg).contains("QLayout: Attempting to add QLayout") == true) { qDebug() << "Layout error"; // <- Put a breakpoint here }
The benefit is then you do not need to recompile Qt just to see where some message gets generated.
After you have found the issue, disable the custom message handler until you find some other message that you need to break on, update the test in the handler, reinstall the hander and debug.
Regards,
-
@Bart_Vandewoestyne, I know the thread is solved but perhaps this can help someone else or yourself in future.
An alternative to what @yeckel said:
I ended up with own debug build of Qt libraries and breakpoints in qWarning()
You can use the qInstallMsgHandler() function to install a hander then add some code like:
if(QString(msg).contains("QLayout: Attempting to add QLayout") == true) { qDebug() << "Layout error"; // <- Put a breakpoint here }
The benefit is then you do not need to recompile Qt just to see where some message gets generated.
After you have found the issue, disable the custom message handler until you find some other message that you need to break on, update the test in the handler, reinstall the hander and debug.
Regards,
@TheBadger said:
You can use the qInstallMsgHandler() function to install a hander then add some code like:
if(QString(msg).contains("QLayout: Attempting to add QLayout") == true) { qDebug() << "Layout error"; // <- Put a breakpoint here }
The benefit is then you do not need to recompile Qt just to see where some message gets generated.
That's brilliant!