Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is there any way to suppress QML Warnings?
QtWS25 Last Chance

Is there any way to suppress QML Warnings?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 5 Posters 1.3k 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.
  • A Offline
    A Offline
    AdarshKale
    wrote on 28 Oct 2023, 19:54 last edited by
    #1

    If there are any QML errors on a currently rendered QML file, we get the WARN-level logs.

    For instance:
    WARN - MainPhonePage.qml : : 851 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:851: TypeError: Cannot read property 'name' of undefined
    WARN - MainPhonePage.qml : : 877 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:877: TypeError: Cannot read property 'phoneNumber' of undefined
    WARN - MainPhonePage.qml : : 876 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:876: TypeError: Cannot read property 'callStatus' of undefined

    Is there any way to suppress these warnings? Or stop logging them to the console as part of warnings?

    G 1 Reply Last reply 28 Oct 2023, 22:08
    0
    • A AdarshKale
      28 Oct 2023, 19:54

      If there are any QML errors on a currently rendered QML file, we get the WARN-level logs.

      For instance:
      WARN - MainPhonePage.qml : : 851 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:851: TypeError: Cannot read property 'name' of undefined
      WARN - MainPhonePage.qml : : 877 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:877: TypeError: Cannot read property 'phoneNumber' of undefined
      WARN - MainPhonePage.qml : : 876 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:876: TypeError: Cannot read property 'callStatus' of undefined

      Is there any way to suppress these warnings? Or stop logging them to the console as part of warnings?

      G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 28 Oct 2023, 22:08 last edited by
      #2

      @AdarshKale remove the cause of the warnings. Are you getting them on start or on close? Maybe you are calling setContextProperty after loading the QML if it's on start. If it's on close one hypothesis is that some of your objects are destroyed before the QML engine.

      A 1 Reply Last reply 29 Oct 2023, 06:49
      2
      • G GrecKo
        28 Oct 2023, 22:08

        @AdarshKale remove the cause of the warnings. Are you getting them on start or on close? Maybe you are calling setContextProperty after loading the QML if it's on start. If it's on close one hypothesis is that some of your objects are destroyed before the QML engine.

        A Offline
        A Offline
        AdarshKale
        wrote on 29 Oct 2023, 06:49 last edited by
        #3

        @GrecKo Yeah, you are right, solving the errors is one of the solutions.
        There are many such warnings that come on startup, and this code is carried over from legacy, and to some of the files we do not have access to modify them, So am looking for some way to suppress these.
        Anywhere in CMake/QMake (.pro) can we restrict the warnings to be printed on the console?
        Thanks

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KH-219Design
          wrote on 30 Oct 2023, 15:37 last edited by
          #4

          You can write your own QtMessageHandler in C++ and use qInstallMessageHandler

          I do this in my project, but I take it far in the other direction: my message handler takes every QML "warning" and makes it into a fatal error!

          So I agree with @GrecKo that what should ideally happen is that the underlying code that provokes warnings should be fixed so as to no longer provoke warnings.

          But I also know the pain of having too much legacy cruft to clean up all at once.

          Here is my code, but as I say, it kind of does the opposite of what you want. But it can stand as a starting point regarding qInstallMessageHandler:

          https://github.com/219-design/qt-qml-project-template-with-ci/blob/f2d453eb664d4/src/util/qml_message_interceptor.cc

          www.219design.com
          Software | Electrical | Mechanical | Product Design

          M A 2 Replies Last reply 31 Oct 2023, 11:47
          0
          • K KH-219Design
            30 Oct 2023, 15:37

            You can write your own QtMessageHandler in C++ and use qInstallMessageHandler

            I do this in my project, but I take it far in the other direction: my message handler takes every QML "warning" and makes it into a fatal error!

            So I agree with @GrecKo that what should ideally happen is that the underlying code that provokes warnings should be fixed so as to no longer provoke warnings.

            But I also know the pain of having too much legacy cruft to clean up all at once.

            Here is my code, but as I say, it kind of does the opposite of what you want. But it can stand as a starting point regarding qInstallMessageHandler:

            https://github.com/219-design/qt-qml-project-template-with-ci/blob/f2d453eb664d4/src/util/qml_message_interceptor.cc

            M Offline
            M Offline
            Markkyboy
            wrote on 31 Oct 2023, 11:47 last edited by Markkyboy
            #5

            Note: I am using QtCreator for SailfishOS, so content may vary between QtCreators used.

            Not sure if this helps out or not, perhaps I misunderstand the question (very likely, I often do) I get something similar but it is not a warning, instead is shown as 'unknown'.

            In my case, this stems from using QtQuickLayouts, so I get such output as ;

            [D] unknown:0 - QQuickLayoutAttached::invalidateItem    
            [D] unknown:0 - QQuickLayoutAttached::invalidateItem   
            [D] unknown:0 - ItemChildAddedChange
            

            such output is spewed out so often, it is hard to see/read warnings and errors I really need to read, I then have to keep scrolling back to see any errors I need to address.

            To combat this, while developing my app, on the Compile Output window frame, there is a small search box, I use this to filter out unwanted messages.

            filter-box.PNG

            unknown-text-added.PNG

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            P 1 Reply Last reply 2 Nov 2023, 15:16
            0
            • M Markkyboy
              31 Oct 2023, 11:47

              Note: I am using QtCreator for SailfishOS, so content may vary between QtCreators used.

              Not sure if this helps out or not, perhaps I misunderstand the question (very likely, I often do) I get something similar but it is not a warning, instead is shown as 'unknown'.

              In my case, this stems from using QtQuickLayouts, so I get such output as ;

              [D] unknown:0 - QQuickLayoutAttached::invalidateItem    
              [D] unknown:0 - QQuickLayoutAttached::invalidateItem   
              [D] unknown:0 - ItemChildAddedChange
              

              such output is spewed out so often, it is hard to see/read warnings and errors I really need to read, I then have to keep scrolling back to see any errors I need to address.

              To combat this, while developing my app, on the Compile Output window frame, there is a small search box, I use this to filter out unwanted messages.

              filter-box.PNG

              unknown-text-added.PNG

              P Offline
              P Offline
              petero3
              wrote on 2 Nov 2023, 15:16 last edited by petero3 11 Feb 2023, 15:16
              #6

              Realise that the question is more about suppressing than fixing, but incase it helps anyone reading, this helped me with some puzzling warnings:
              https://www.qt.io/blog/compiling-qml-to-c-fixing-unqualfied-access

              1 Reply Last reply
              0
              • K KH-219Design
                30 Oct 2023, 15:37

                You can write your own QtMessageHandler in C++ and use qInstallMessageHandler

                I do this in my project, but I take it far in the other direction: my message handler takes every QML "warning" and makes it into a fatal error!

                So I agree with @GrecKo that what should ideally happen is that the underlying code that provokes warnings should be fixed so as to no longer provoke warnings.

                But I also know the pain of having too much legacy cruft to clean up all at once.

                Here is my code, but as I say, it kind of does the opposite of what you want. But it can stand as a starting point regarding qInstallMessageHandler:

                https://github.com/219-design/qt-qml-project-template-with-ci/blob/f2d453eb664d4/src/util/qml_message_interceptor.cc

                A Offline
                A Offline
                AdarshKale
                wrote on 16 Nov 2023, 06:29 last edited by
                #7

                @KH-219Design Thank you So much for the reference solution.
                will tryout this.
                Thanks

                1 Reply Last reply
                0
                • M majorRonk referenced this topic on 24 Mar 2025, 09:47

                • Login

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