Ubuntu16下构建Qt Quick应用报错:Unknown module(s) in QT:qml quick 解决方法
Hey there, let's fix that frustrating error you're hitting when building your first Qt Quick Controls app on Ubuntu 16. This is a super common issue, almost always tied to missing Qt development packages that aren't included in a default setup. Here's how to get it sorted:
1. 先安装缺失的Qt开发依赖包
Ubuntu 16's software repository splits Qt modules into separate packages, so you'll need to explicitly install the ones for QML and Quick. Open a terminal and run these commands:
sudo apt-get update sudo apt-get install qtdeclarative5-dev qtquickcontrols2-5-dev
A quick breakdown:
qtdeclarative5-devcovers the core QML module's headers and libraries, which is required for theqmlmodule referenceqtquickcontrols2-5-devis for Qt Quick Controls 2. If your project uses the older Controls 1, swap this forqtquickcontrols5-devinstead.
2. Check Qt Creator's Kit Configuration
If the error persists after installing packages, Qt Creator might not be picking up the newly installed modules. Let's verify your setup:
- Open Qt Creator, go to
Tools→Optionsfrom the top menu - Select
Build & Runon the left, then switch to theKitstab - Pick the kit you're using (usually something like "Desktop Qt 5.x.x GCC 64bit") and click
Detailson the right - Check that the
Qt Versionpoints to the correct qmake executable. If it looks off, clickManagenext toQt Version - On the Qt Versions page, select your Qt 5 installation and click
Refresh—this should force Qt Creator to scan for all installed modules, including qml and quick - If the modules still don't show up, manually point to the default Ubuntu 16 qmake path:
/usr/lib/x86_64-linux-gnu/qt5/bin/qmake
3. Verify qmake Can Detect the Modules
To rule out system-level issues, test qmake directly in the terminal:
First, check if the QML installation path is recognized:
qmake -query QT_INSTALL_QML
You should get a valid path like /usr/lib/x86_64-linux-gnu/qt5/qml. Then list all available modules:
qmake -qt=qt5 -modules
Look for qml and quick in the output. If they're present, the problem is definitely in Qt Creator's kit configuration—just refresh it again as step 2 describes.
4. Last Resort: Manually Specify Module Path (Rarely Needed)
If everything else fails, you can explicitly add the module path to your project's .pro file, though this shouldn't be necessary if you installed the packages correctly:
QT += qml quick QML_IMPORT_PATH += /usr/lib/x86_64-linux-gnu/qt5/qml
内容的提问来源于stack exchange,提问作者vico




