Maya 使用C++ QT

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

然后創(chuàng)建Maya的模板項(xiàng)目,一定要勾選OpenMayaUI


image.png

重新定向下項(xiàng)目


image.png

在項(xiàng)目屬性里加入QT的依賴


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文件名:工程---屬性---配置屬性---鏈接器---輸入---附加依賴項(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里寫入測(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容