Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qt messages in console: where do the problems occur?
QtWS25 Last Chance

[SOLVED] Qt messages in console: where do the problems occur?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bart_Vandewoestyne
    wrote on last edited by Bart_Vandewoestyne
    #1

    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

    JKSHJ B 2 Replies Last reply
    0
    • B Bart_Vandewoestyne

      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

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      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() on FooBarWidget

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bart_Vandewoestyne
        wrote on last edited by
        #3

        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!

        yeckelY 1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • B Bart_Vandewoestyne

            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!

            yeckelY Offline
            yeckelY Offline
            yeckel
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Bart_Vandewoestyne

                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

                B Offline
                B Offline
                Bart_Vandewoestyne
                wrote on last edited by
                #7

                @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!

                1 Reply Last reply
                0
                • TheBadgerT Offline
                  TheBadgerT Offline
                  TheBadger
                  wrote on last edited by
                  #8

                  @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,


                  Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

                  JKSHJ 1 Reply Last reply
                  2
                  • TheBadgerT TheBadger

                    @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,

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    @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!

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved