如何使用mingw32安装Box2D-qml

How to install Box2D-qml with mingw32

我的环境: Qt 5.3.1 + Mingw32 Windows 7

我厌倦了这些:

  1. C:\Qt\Qt5.3.1.3\mingw482_32\imports中提取box2d-qml并重命名为Box2D
  2. 打开 cmd 并 cd 进入 Box2D 的目录。
  3. 在cmd中输入qmake,无输出
  4. 输入mingw32-make,无错误输出
  5. 输入mingw32-make install,无错误输出。 Box2D.2.0 是在 C:\Qt\Qt5.3.1.3\mingw482_32\qml 目录下生成的。

然后我创建空的快速项目并将 import Box2D 2.0 添加到 qml 中。 将鼠标光标移动到import Box2D 2.0,QtCreator弹出提示信息:

但是当我 运行 时出现错误:

QQmlApplicationEngine failed to load component
qrc:///main.qml:3 plugin cannot be loaded for module "Box2D": ?v???O?C?? 'C:/Qt/Qt5.3.1/5.3/mingw482_32/qml/Box2D.2.0/Box2D.dll' ????? Qt ?????????????C?u???????g?p?????????B (?f?o?b?N???????[?X?????C?u?????????g?p???邱??????????)

主要Cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

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

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

    return app.exec();
}

您有 2 个选项来使用该插件:

  1. 作为系统范围的 QML 插件安装到 $QTPATH/qml(或 $QTPATH/imports)文件夹中。在这种情况下,您只需执行后续步骤:

    • 从Github下载源码并用QtCreator打开(不要放到系统文件夹,把源码放到某个用户文件夹)
    • 转到“项目”选项卡/运行/添加部署步骤
    • install 添加到 Make arguments
    • 转到“编辑”选项卡,右键单击项目并 select Run qmake
    • 现在构建项目(不要忘记设置发布配置文件)
    • 右键单击项目并 select Deploy;
    • 插件 dll(包括您需要的所有内容、Box2D 代码等)将安装到 qt 文件夹中。

.

  1. 将插件编译为项目的一部分。在这种情况下,您只需执行后续步骤:

    • 从Github下载源码并将插件源码文件夹放入您的项目文件夹(例如myproject/qml-box2d/)
    • 将行添加到您的 .pro 文件中:include(qml-box2d/box2d_lib.pri)
    • 将此代码添加到您的 main.cpp 文件中:

    #include <box2dplugin.h> // <-- this line
    int main(int argc, char *argv[])
    {
    ...
    Box2DPlugin plugin;            // and these
    plugin.registerTypes("Box2D"); // 2 lines
    ...
    }
    
    • 重新运行 qmake 并重新编译项目。现在您可以在 QML 文件中使用 Box2D 项。