下載QT版本:http://download.qt.io/archive/qt/
然后創(chuàng)建Maya的模板項(xiàng)目勃刨,一定要勾選OpenMayaUI
image.png
重新定向下項(xiàng)目
image.png
在項(xiàng)目屬性里加入QT的依賴(lài)
image.png
1踏揣、添加工程的頭文件目錄:工程---屬性---配置屬性---c/c++---常規(guī)---附加包含目錄:加上頭文件存放目錄顾犹。
添加的路徑就是上面下載的QT安裝位置里面的include文件夾
image.png
image.png
2、添加文件引用的lib靜態(tài)庫(kù)路徑:工程---屬性---配置屬性---鏈接器---常規(guī)---附加庫(kù)目錄:加上lib文件存放目錄滋恬。
image.png
image.png
3、然后添加工程引用的lib文件名:工程---屬性---配置屬性---鏈接器---輸入---附加依賴(lài)項(xiàng):加上lib文件名。
就是把這個(gè)路徑的下的.lib的名字復(fù)制進(jìn)去就行了
image.png
image.png
然后點(diǎn)擊應(yīng)用
再cpp文件里導(dǎo)入頭文件
#include <maya/MQtUtil.h>
#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>
再doIt里寫(xiě)入測(cè)試代碼
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
執(zhí)行cmd
image.png
成功
image.png