Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to disable the Strict Equality Comparison warning
Forum Updated to NodeBB v4.3 + New Features

How to disable the Strict Equality Comparison warning

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
16 Posts 5 Posters 1.7k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    w.tkm
    wrote on last edited by w.tkm
    #1

    Hi.
    I want to disable the strict equality comparison warning.
    Is there any way to disable it?

    1 Reply Last reply
    0
    • W w.tkm

      @mrjj
      It's an extreme example,

      property int i
      
          Component.onCompleted: {
              i = Math.floor(Math.random() * 10)
          }
      
          onClicked: {
              if( inputText.text == i ){ //M126 is shown here
                  console.log("OK")
              }
              else {
                  console.log("NO")
             }
          }
      

      I know why it's showing.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #12

      @w-tkm said in How to disable the Strict Equality Comparison warning:

      I know why it's showing.

      You could try to force int conversion:

      onClicked: {
              if( parseInt(inputText.text, 10) === i) ){ 
                  console.log("OK")
              }
              else {
                  console.log("NO")
             }
          }
      

      Or to disable the warning:

       onClicked: {
              // @disable-check M126
              if( inputText.text == i ){ 
                  console.log("OK")
              }
              else {
                  console.log("NO")
             }
          }
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      W 1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        For which compiler?

        Often yes you can.

        W 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          For which compiler?

          Often yes you can.

          W Offline
          W Offline
          w.tkm
          wrote on last edited by
          #3

          @mrjj
          I use MSVC and MinGW.

          mrjjM 1 Reply Last reply
          0
          • W w.tkm

            @mrjj
            I use MSVC and MinGW.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #4

            @w-tkm

            When you compile, does it then show the warning id in output ?
            like -Wuninitialized etc

            I need something more than "Strict Equality Comparison" to find the key as
            i only get javascript hits on that term so Im not sure which you actually want to supress.

            Cab you list the actual warning you get ?

            The solution is something like
            QMAKE_CXXFLAGS += -Wno-enum-compare

            but we need to know the actual thing it complains about so we kill the right one :)

            W 1 Reply Last reply
            0
            • mrjjM mrjj

              @w-tkm

              When you compile, does it then show the warning id in output ?
              like -Wuninitialized etc

              I need something more than "Strict Equality Comparison" to find the key as
              i only get javascript hits on that term so Im not sure which you actually want to supress.

              Cab you list the actual warning you get ?

              The solution is something like
              QMAKE_CXXFLAGS += -Wno-enum-compare

              but we need to know the actual thing it complains about so we kill the right one :)

              W Offline
              W Offline
              w.tkm
              wrote on last edited by
              #5

              @mrjj
              No, It show as line annotations.
              Error code is M126.
              I don't have any problems that I can't compile, but I asked because it bothers me while coding.

              mrjjM 1 Reply Last reply
              0
              • W w.tkm

                @mrjj
                No, It show as line annotations.
                Error code is M126.
                I don't have any problems that I can't compile, but I asked because it bothers me while coding.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #6

                @w-tkm

                Ah that is the clang code model.
                https://doc.qt.io/qtcreator/creator-clang-codemodel.html

                You can either disable the plugin completely
                https://forum.qt.io/topic/100762/qt-creator-clang-code-model-problems-collection

                Or go to option and c++ / code model and see if you can add remove it.
                (often you can tool tip the warning and it tells what option)

                Just make a copy of current default settings then you can change it.

                Then go look
                https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

                and see if sounds like the warning.

                alt text

                W 1 Reply Last reply
                0
                • mrjjM mrjj

                  @w-tkm

                  Ah that is the clang code model.
                  https://doc.qt.io/qtcreator/creator-clang-codemodel.html

                  You can either disable the plugin completely
                  https://forum.qt.io/topic/100762/qt-creator-clang-code-model-problems-collection

                  Or go to option and c++ / code model and see if you can add remove it.
                  (often you can tool tip the warning and it tells what option)

                  Just make a copy of current default settings then you can change it.

                  Then go look
                  https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

                  and see if sounds like the warning.

                  alt text

                  W Offline
                  W Offline
                  w.tkm
                  wrote on last edited by
                  #7

                  @mrjj
                  I understood well, but I couldn't find description of strict equality comparison in Warning Options.

                  mrjjM 1 Reply Last reply
                  0
                  • W w.tkm

                    @mrjj
                    I understood well, but I couldn't find description of strict equality comparison in Warning Options.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @w-tkm

                    Hi
                    Can you give me a code snippet that gives that warning ?
                    Then maybe I can get hint from that ?

                    W 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @w-tkm

                      Hi
                      Can you give me a code snippet that gives that warning ?
                      Then maybe I can get hint from that ?

                      W Offline
                      W Offline
                      w.tkm
                      wrote on last edited by w.tkm
                      #9

                      @mrjj
                      It's an extreme example,

                      property int i
                      
                          Component.onCompleted: {
                              i = Math.floor(Math.random() * 10)
                          }
                      
                          onClicked: {
                              if( inputText.text == i ){ //M126 is shown here
                                  console.log("OK")
                              }
                              else {
                                  console.log("NO")
                             }
                          }
                      

                      I know why it's showing.

                      J.HilkJ mrjjM KroMignonK 3 Replies Last reply
                      0
                      • W w.tkm

                        @mrjj
                        It's an extreme example,

                        property int i
                        
                            Component.onCompleted: {
                                i = Math.floor(Math.random() * 10)
                            }
                        
                            onClicked: {
                                if( inputText.text == i ){ //M126 is shown here
                                    console.log("OK")
                                }
                                else {
                                    console.log("NO")
                               }
                            }
                        

                        I know why it's showing.

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by J.Hilk
                        #10

                        @w-tkm why don't you do a proper comparison, instead of disabling the warnings ?

                        if( parseInt(inputText.text) === i )
                        //or
                        if(inputText.text === i.toString())
                        

                        or the lazy way:

                        inputText.text === "" +i
                        

                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        1
                        • W w.tkm

                          @mrjj
                          It's an extreme example,

                          property int i
                          
                              Component.onCompleted: {
                                  i = Math.floor(Math.random() * 10)
                              }
                          
                              onClicked: {
                                  if( inputText.text == i ){ //M126 is shown here
                                      console.log("OK")
                                  }
                                  else {
                                      console.log("NO")
                                 }
                              }
                          

                          I know why it's showing.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          @w-tkm

                          aahhh in QML :)

                          I'm afraid you cannot configure it.

                          W 1 Reply Last reply
                          0
                          • W w.tkm

                            @mrjj
                            It's an extreme example,

                            property int i
                            
                                Component.onCompleted: {
                                    i = Math.floor(Math.random() * 10)
                                }
                            
                                onClicked: {
                                    if( inputText.text == i ){ //M126 is shown here
                                        console.log("OK")
                                    }
                                    else {
                                        console.log("NO")
                                   }
                                }
                            

                            I know why it's showing.

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by KroMignon
                            #12

                            @w-tkm said in How to disable the Strict Equality Comparison warning:

                            I know why it's showing.

                            You could try to force int conversion:

                            onClicked: {
                                    if( parseInt(inputText.text, 10) === i) ){ 
                                        console.log("OK")
                                    }
                                    else {
                                        console.log("NO")
                                   }
                                }
                            

                            Or to disable the warning:

                             onClicked: {
                                    // @disable-check M126
                                    if( inputText.text == i ){ 
                                        console.log("OK")
                                    }
                                    else {
                                        console.log("NO")
                                   }
                                }
                            

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            W 1 Reply Last reply
                            1
                            • mrjjM mrjj

                              @w-tkm

                              aahhh in QML :)

                              I'm afraid you cannot configure it.

                              W Offline
                              W Offline
                              w.tkm
                              wrote on last edited by
                              #13

                              @mrjj
                              Oh,sorry...I should have told you earlier...

                              1 Reply Last reply
                              0
                              • KroMignonK KroMignon

                                @w-tkm said in How to disable the Strict Equality Comparison warning:

                                I know why it's showing.

                                You could try to force int conversion:

                                onClicked: {
                                        if( parseInt(inputText.text, 10) === i) ){ 
                                            console.log("OK")
                                        }
                                        else {
                                            console.log("NO")
                                       }
                                    }
                                

                                Or to disable the warning:

                                 onClicked: {
                                        // @disable-check M126
                                        if( inputText.text == i ){ 
                                            console.log("OK")
                                        }
                                        else {
                                            console.log("NO")
                                       }
                                    }
                                
                                W Offline
                                W Offline
                                w.tkm
                                wrote on last edited by
                                #14

                                @KroMignon
                                Thanks. I did it.
                                It seems to there is no setting in the options.

                                KroMignonK 1 Reply Last reply
                                0
                                • W w.tkm

                                  @KroMignon
                                  Thanks. I did it.
                                  It seems to there is no setting in the options.

                                  KroMignonK Offline
                                  KroMignonK Offline
                                  KroMignon
                                  wrote on last edited by
                                  #15

                                  @w-tkm said in How to disable the Strict Equality Comparison warning:

                                  It seems to there is no setting in the options.

                                  Do mean a global disable of this warning?
                                  AFAIK, there is no way to do it.
                                  But warnings are there to help you the write clean QML code, as QML is a declarative language, it is hard to be sure to write a clean code, so warnings are welcome to highlight not "so clean code" ;)

                                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                  1 Reply Last reply
                                  2
                                  • Z Offline
                                    Z Offline
                                    zenzop
                                    wrote on last edited by zenzop
                                    #16

                                    it worked for me, thanks a lot.. .

                                    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