简体   繁体   English

cmake Qt5 失败并显示“未安装模块 QtQuick”

[英]cmake Qt5 failes with "module QtQuick is not installed'

I have tried a simple Qt Qml example and I am not able to build it.我尝试了一个简单的 Qt Qml 示例,但我无法构建它。 I already googled and found a dozen similar problems, but none of the recommendations helped me.我已经用谷歌搜索并发现了十几个类似的问题,但没有一个建议对我有帮助。 My code looks like this:我的代码如下所示:

main.cpp主.cpp

#include <QtGui/QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine(QUrl("qrc:main.qml"));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();
}

main.qml主要.qml

import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow
{
    visible: true
    width: 640
    height: 480
    title: qsTr("Minimal Qml")
}

qml.qrc qml.qrc

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>
</RCC>

and my CMakeLists.txt和我的 CMakeLists.txt

find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED)

qt5_add_resources(QT_RESOURCES qml.qrc)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(PROJECT "qmltest")
project(${PROJECT})

add_executable(${PROJECT} main.cpp  ${QT_RESOURCES})

target_link_libraries(${PROJECT}
    Qt5::WinMain
    Qt5::Core
    Qt5::Qml
    Qt5::Quick
)

I used windeployqt to get all librarys into the right place.我使用 windeployqt 将所有库放到正确的位置。 The programm starts on my Windows machine but the console output ends with:该程序在我的 Windows 机器上启动,但控制台 output 以:

QQmlApplicationEngine failed to load component
qrc:main.qml:2:1: module "QtQuick.Controls" is not installed
qrc:main.qml:1:1: module "QtQuick" is not installed
qrc:main.qml:2:1: module "QtQuick.Controls" is not installed
qrc:main.qml:1:1: module "QtQuick" is not installed

Path to the app after deploying it:部署后应用程序的路径:

<DIR>   bearer
            qgenericbearerd.dll
<DIR>   iconengines
            qsvgicond.dll
<DIR>   imageformats
            qgifd.dll
            qicnsd.dll
            qicod.dll
            qjpegd.dll
            qsvgd.dll
            qtgad.dll
            qtiffd.dll
            qwbmpd.dll
            qwebpd.dll
<DIR>   platforminputcontexts
            qtvirtualkeyboardplugind.dll
<DIR>   platforms
            qwindowsd.dll
<DIR>   qmltooling
            qmldbg_debuggerd.dll
            qmldbg_inspectord.dll
            qmldbg_locald.dll
            qmldbg_messagesd.dll
            qmldbg_natived.dll
            qmldbg_nativedebuggerd.dll
            qmldbg_previewd.dll
            qmldbg_profilerd.dll
            qmldbg_quickprofilerd.dll
            qmldbg_serverd.dll
            qmldbg_tcpd.dll
<DIR>   scenegraph
            qsgd3d12backendd.dll
<DIR>   styles
            qwindowsvistastyled.dll
<DIR>   translations
            ...
<DIR>   virtualkeyboard
            qtvirtualkeyboard_hanguld.dll
            qtvirtualkeyboard_openwnnd.dll
            qtvirtualkeyboard_pinyind.dll
            qtvirtualkeyboard_tcimed.dll
            qtvirtualkeyboard_thaid.dll
        concrt140d.dll
        d3dcompiler_47.dll
        libEGLd.dll
        libGLESv2d.dll
        msvcp140d.dll
        msvcp140d_atomic_wait.dll
        msvcp140d_codecvt_ids.dll
        msvcp140_1d.dll
        msvcp140_2d.dll
        qmltest.exe
        qmltest.ilk
        qmltest.pdb
        Qt5Cored.dll
        Qt5Guid.dll
        Qt5Networkd.dll
        Qt5Qmld.dll
        Qt5Quickd.dll
        Qt5Svgd.dll
        Qt5Widgetsd.dll
        vccorlib140d.dll
        vcruntime140d.dll

I'm using Qt 5.15 open source.我正在使用 Qt 5.15 开源。 I built it and installed it on WIndows7.我构建了它并将其安装在 WIndows7 上。 Any ideas?有任何想法吗? Thank you!谢谢!

For one of our Windows app, we deploy over 1700 files.对于我们的 Windows 应用程序之一,我们部署了 1700 多个文件。 The directory structure looks roughly like this:目录结构大致如下:

<DIR> MyQtApp_Bin_Dir
          MyQtApp.exe
          COPY C:\Qt\Qt5.15.6\5.15.6\msvc2019_64\bin\*.dll
          COPY C:\Qt\Qt5.15.6\5.15.6\msvc2019_64\resources\*.*
          COPY C:\Qt\Qt5.15.6\5.15.6\msvc2019_64\plugins\*
          COPY VISUALSTUDIO_REDISTRIBUTABLES_HERE

<DIR> MyQtApp_Bin_Dir\qml
          COPY C:\Qt\Qt5.15.6\5.15.6\msvc2019_64\qml\*

In the directory dump that you posted, the qml folder appears to be absent.在您发布的目录转储中, qml文件夹似乎不存在。 The content directly controls the import statements that you are having issue with.内容直接控制您遇到问题的import语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM