You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Ubuntu16下构建Qt Quick应用报错:Unknown module(s) in QT:qml quick 解决方法

解决Ubuntu 16下Qt构建报错"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-dev covers the core QML module's headers and libraries, which is required for the qml module reference
  • qtquickcontrols2-5-dev is for Qt Quick Controls 2. If your project uses the older Controls 1, swap this for qtquickcontrols5-dev instead.

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 ToolsOptions from the top menu
  • Select Build & Run on the left, then switch to the Kits tab
  • Pick the kit you're using (usually something like "Desktop Qt 5.x.x GCC 64bit") and click Details on the right
  • Check that the Qt Version points to the correct qmake executable. If it looks off, click Manage next to Qt 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

火山引擎 最新活动