JavaScript and QML Checks

To run static checks, go to Tools > QML/JS > Run Checks or press Ctrl+Shift+C.

View the results in the QML and QML Analysis filters in Issues.

Enabling and Disabling Messages

To enable and disable QML and JavaScript messages:

  1. Go to Preferences > Qt Quick > QML/JS Editing.
  2. Select Use customized static analyzer.

    {QML/JS Editing tab in Qt Quick preferences}

  3. In Enabled, select the messages that you want to see.
  4. To disable messages for non-Qt Quick UI files, select them in Disable messages for non Qt Quick UI. You cannot enable messages just for non-Qt Quick UI files.

JavaScript and QML Error Codes

Many of the error messages are similar to the ones in Douglas Crockford's JSLint tool. For more information about JSLint errors, see JSLint Error Explanations.

IdSeverityMessageDescription
M1ErrorInvalid value for enum
M2ErrorEnum value must be a string or a number
M3ErrorNumber value expected
M4ErrorBoolean value expected
M5ErrorString value expected
M6ErrorInvalid URL
M7WarningFile or directory does not exist
M8ErrorInvalid color
M9ErrorAnchor line expected
M10ErrorDuplicate property bindingSee also: Duplicate key '{a}'.
M11ErrorId expectedSee also: Expected an identifier and instead saw '{a}' (a reserved word).
M14ErrorInvalid idSee also: Expected an identifier and instead saw '{a}' (a reserved word).
M15ErrorDuplicate idIds in a file must be unique. See also: Duplicate key '{a}'.
M16ErrorInvalid property name name
M17ErrorName does not have members
M18ErrorField is not a member of object
M19WarningAssignment in conditionIt could be a typing error. If it is intentional, wrap the assignment in parentheses.
M20WarningUnterminated non-empty case blockCase blocks should either be empty or end in a flow control statement such as break, return or continue. Alternatively you can indicate intentional fall through by ending with a // fall through comment.
M23WarningDo not use evalSee also: eval is evil.
M28WarningUnreachableIndicates that the underlined statement will never be executed.
M29WarningDo not use withSee also: Unexpected 'with'.
M30WarningDo not use comma expressions
M31WarningUnnecessary message suppression
M103WarningName is already a formal parameter
M104WarningName is already a function
M105WarningVar name is used before its declaration
M106WarningName already is a var
M107WarningName is declared more than onceVariables declared in a function are always visible everywhere in the function, even when declared in nested blocks or for statement conditions. Redeclaring a variable has no effect.
M108WarningFunction name is used before its declarationSee also: {a} was used before it was defined.
M109WarningDo not use Boolean as a constructorSee also: Do not use {a} as a constructor.
M110WarningDo not use String as a constructorSee also: Do not use {a} as a constructor.
M111WarningDo not use Object as a constructorSee also: Do not use {a} as a constructor.
M112WarningDo not use Array as a constructorSee also: Do not use {a} as a constructor.
M113WarningDo not use Function as a constructorSee also: Do not use {a} as a constructor.
M114HintThe function keyword and the opening parenthesis should be separated by a single spaceSee also: Expected exactly one space between {a} and {b}.
M115WarningDo not use stand-alone blocksBlocks do not affect variable scoping. Thus blocks that are not associated to if, while, etc. have no effect and should be avoided.
M116WarningDo not use void expressions
M117WarningConfusing plusesSee also: Confusing pluses.
M119WarningConfusing minusesSee also: Confusing minuses.
M121HintDeclare all function vars on a single line
M123HintUnnecessary parentheses
M126Warning== and != may perform type coercion, use === or !== to avoid itThe non-strict equality comparison is allowed to convert its arguments to a common type. That can lead to unexpected results such as ' \t\r\n' == 0 being true. Use the strict equality operators === and !== and be explicit about conversions you require.
M127WarningExpression statements should be assignments, calls or delete expressions only
M128ErrorA state cannot have the specified child item
M129ErrorType cannot be instantiated recursively
M201HintPlace var declarations at the start of a functionSee also: Move 'var' declarations to the top of the function.
M202HintUse only one statement per line
M220ErrorThis type (type name) is not supported as a root element of a UI file (.ui.qml)For more information about supported QML types, see UI Files.
M221ErrorThis type (type name) is not supported in a UI file (.ui.qml)For more information about supported QML types, see UI Files.
M222ErrorFunctions are not supported in a UI file (.ui.qml)For a list of supported JavaScript functions, see Supported Methods.
M223ErrorJavaScript blocks are not supported in a UI file (.ui.qml)For more information about supported features, see UI Files.
M224ErrorBehavior type is not supported in a UI file (.ui.qml)For more information about supported QML types, see UI Files.
M225ErrorStates are only supported in the root item in a UI file (.ui.qml)For more information about supported features, see UI Files.
M226ErrorReferencing the parent of the root item is not supported in a UI file (.ui.qml)For more information about supported features, see UI Files.
M227ErrorDo not mix translation functions in a UI file (.ui.qml)Even though several different translation functions, such as qsTr and qsTrId are supported, you should pick one and use it consistently within a UI file. For more information, see Qt QML Methods.
M300ErrorUnknown component
M301ErrorCould not resolve the prototype name of object
M302ErrorCould not resolve the prototype name
M303ErrorPrototype cycle, the last non-repeated component is name
M304ErrorInvalid property type name
M305Warning== and != perform type coercion, use === or !== to avoid itSee M126.
M306WarningCalls of functions that start with an uppercase letter should use newBy convention, functions that start with an uppercase letter are constructor functions that should only be used with new.
M307WarningUse new only with functions that start with an uppercase letterSee also: Do not use {a} as a constructor.
M308WarningDo not use Number as a constructorSee also: Do not use {a} as a constructor.
M309HintUse spaces around binary operators
M310WarningUnintentional empty block, use ({}) for empty object literal
M311HintUse type instead of var or variant to improve performance
M312ErrorMissing property number
M313ErrorObject value expected
M314ErrorArray value expected
M315ErrorValue value expected
M316ErrorMaximum number value is number
M317ErrorMinimum number value is number
M318ErrorMaximum number value is exclusive
M319ErrorMinimum number value is exclusive
M320ErrorString value does not match required pattern
M321ErrorMinimum string value length is number
M322ErrorMaximum string value length is number
M323ErrorNumber elements expected in array valueSee also: The array literal notation [] is preferable.
M324ErrorHit maximum recursion limit visiting AST, the code model will be unreliable and most likely invalid
M325WarningLogical value does not depend on actual valuesRemoved: This warning is no longer being used since Qt Creator version 12.
M326ErrorComponents are only allowed to have a single child elementFor more information, see Component.
M327WarningComponents require a child elementFor more information, see Component.
M400WarningDuplicate importAn import statement has been added twice. For more information, see Import Statements.
M401ErrorDo not reference the root item as aliasThe alias property cannot reference the root component directly. Create an instance of the component instead.
M402WarningAvoid referencing the root item in a hierarchyThe alias property cannot reference the root component in a hierarchy. Create an instance of the component instead.

Resetting the Code Model

If you see the following error messages after you add a new QML module, try building the project and then resetting the code model:

  • QML module not found.
  • Unknown Component (M300).

To see an error message, move the mouse pointer over code that Qt Creator underlines in the code editor or when you open a QML file in Qt Design Studio.

To reset the code model, select Tools > QML/JS > Reset Code Model.

See also Check code syntax, Using QML Modules with Plugins, and Analyzing Code.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.