Maya 使用C++ QT

下载QT版本:http://download.qt.io/archive/qt/

然后创建Maya的模板项目,一定要勾选OpenMayaUI


image.png

重新定向下项目


image.png

在项目属性里加入QT的依赖


image.png

1、添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录。

添加的路径就是上面下载的QT安装位置里面的include文件夹

image.png

image.png

2、添加文件引用的lib静态库路径:工程---属性---配置属性---链接器---常规---附加库目录:加上lib文件存放目录。


image.png
image.png

3、然后添加工程引用的lib文件名:工程---属性---配置属性---链接器---输入---附加依赖项:加上lib文件名。

就是把这个路径的下的.lib的名字复制进去就行了

image.png
image.png

然后点击应用

再cpp文件里导入头文件

#include <maya/MQtUtil.h>
#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>

再doIt里写入测试代码

QWidget* w = new QWidget(MQtUtil::mainWindow());
w->resize(500, 500);
w->setWindowFlags(Qt::Window);
w->setWindowTitle("CppQT");

QPushButton* test_button = new QPushButton("Test");
test_button->setParent(w);
test_button->move(0, 0);

w->show();

完整CPP

#include "CppQTCmd.h"
#include <maya/MGlobal.h>
#include <maya/MQtUtil.h>
#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>

MStatus CppQT::doIt( const MArgList& )
//
//  Description:
//      implements the MEL CppQT command.
//
//  Arguments:
//      args - the argument list that was passes to the command from MEL
//
//  Return Value:
//      MS::kSuccess - command succeeded
//      MS::kFailure - command failed (returning this value will cause the 
//                     MEL script that is being run to terminate unless the
//                     error is caught using a "catch" statement.
//
{
    MStatus stat = MS::kSuccess;
    QWidget* w = new QWidget(MQtUtil::mainWindow());
    w->resize(500, 500);
    w->setWindowFlags(Qt::Window);
    w->setWindowTitle("CppQT");

    QPushButton* test_button = new QPushButton("Test");
    test_button->setParent(w);
    test_button->move(0, 0);

    w->show();
    // Typically, the doIt() method only collects the infomation required
    // to do/undo the action and then stores it in class members.  The 
    // redo method is then called to do the actuall work.  This prevents
    // code duplication.
    //
    return redoIt();
}

然后编译


image.png

在maya插件编辑器里加入mll


image.png

执行cmd
image.png

成功

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容