How to disable the Strict Equality Comparison warning
-
@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.
@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") } }
-
Hi
For which compiler?Often yes you can.
-
@w-tkm
When you compile, does it then show the warning id in output ?
like -Wuninitialized etcI 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-comparebut we need to know the actual thing it complains about so we kill the right one :)
-
@w-tkm
When you compile, does it then show the warning id in output ?
like -Wuninitialized etcI 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-comparebut we need to know the actual thing it complains about so we kill the right one :)
-
@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.@w-tkm
Ah that is the clang code model.
https://doc.qt.io/qtcreator/creator-clang-codemodel.htmlYou can either disable the plugin completely
https://forum.qt.io/topic/100762/qt-creator-clang-code-model-problems-collectionOr 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.htmland see if sounds like the warning.
-
@w-tkm
Ah that is the clang code model.
https://doc.qt.io/qtcreator/creator-clang-codemodel.htmlYou can either disable the plugin completely
https://forum.qt.io/topic/100762/qt-creator-clang-code-model-problems-collectionOr 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.htmland see if sounds like the warning.
-
@mrjj
I understood well, but I couldn't find description of strict equality comparison in Warning Options.@w-tkm
Hi
Can you give me a code snippet that gives that warning ?
Then maybe I can get hint from that ? -
@w-tkm
Hi
Can you give me a code snippet that gives that warning ?
Then maybe I can get hint from that ? -
@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.
@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
-
@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.
@w-tkm
aahhh in QML :)
I'm afraid you cannot configure it.
-
@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.
@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-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") } }
@KroMignon
Thanks. I did it.
It seems to there is no setting in the options. -
@KroMignon
Thanks. I did it.
It seems to there is no setting in the options.@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" ;)