Warnings Occurred While Importing

This warning category contains multiple warnings:

Failed To Import Module

What happened?

The module imported via import statement was not found.

This can be caused, for example, by

  • a typo in the import statement, or
  • a user-defined module that was not built, or
  • a wrong import 路径 ,或
  • a missing module

Why is this bad?

The application can't run because it can't find a module it relies on.

范例

Typo In The Import Statement

import QtQuicky // not ok: typo in module name
Item {
}
					

You can fix this warning by correcting the typo:

import QtQuick // ok: no typo in module name
Item {
}
					

User-Defined Module That Was Not Built

Some tooling like QML 语言服务器 or qmllint can't find user-defined modules when they are not built. If your project defines the QML Module you are trying to import, then the QML tooling will not find it until you build it.

注意: If building the module does not help when using QML 语言服务器 , follow the instructions in QML Language Server setup instructions and make sure that you communicate the correct build folder to QML Language Server.

Wrong Import Path

Please refer to the QML import path documentation and to the debugging module import documentation for more information about import paths.

Missing Module

If the previous sections did not help to find the imported module, it might be missing. This might be caused by a missing dependency. When using external libraries, verify that they are actually installed, and that their modules end up in an import 路径 .

Component Was Not Found

What happened?

Some component was not found.

Why is this bad?

The application can't run because it can't instantiate the non-found component.

范例

Typo In The Component Name

import QtQuick
Item {
    Itemy {} // not ok: typo in name
}
					

You can fix this warning by correcting the typo:

import QtQuick
Item {
    Item {} // ok: no typo in name
}
					

Missing Import Statement

Item { // not ok: must be imported from QtQuick first
}
					

You can fix this warning by adding the missing module import:

import QtQuick
Item { // ok: was imported from QtQuick
}
					

Import Qualifier must start with a capital letter

What happened?

Some imported module has an invalid qualifier.

Why is this bad?

The module imported with this invalid qualifier can't be used.

范例

import QtQuick as qq
qq.Item {
}
					

You can fix this warning by making the import qualifier start with an upper case letter:

import QtQuick as Qq
Qq.Item {
}
					

Unknown Import Syntax

What happened?

An import statement is using an invalid import syntax .

Why is this bad?

The application can't run because it can't import a module it relies on.

范例

import "¯\(ツ)/¯:/path/to/Module"
import QtQuick
Item {
}
					

You can fix this warning by using URLs that have an allowed scheme:

import "qrc:/path/to/Module"
import QtQuick
Item {
}
					

注意: This example assumes that you are not using URL handlers .

另请参阅 import 语句 .