Thursday, April 8, 2010

Developing custom Qt UI widgets for Maya 2011: OMFG it works!

Well after much stuffing around I finally got this working.  It was one of those problems that had several major pieces that all need to fit.


These are the major things I had to work out:
1.        You must compile your widget plugin with the same Qt SDK version as Maya.  Maya 2011 pre-release uses 4.5.3. 
2.       Your plugin DLL and therefore the base Qt libraries must be compiled with the same compiler that was used to create Maya.  On windows this is MS Visual Studio 2008.  I don’t know about other platforms sorry.
3.       It’s best if you put your plugin DLL in the
C:\Program Files (x86)\Autodesk\Maya2011\qt-plugins\designer\

Now basically what we need to do is compile Qt from scratch using nmake which is the Visual Studio compiler.  We are also setting up Visual Studio as our main development environment so your final plugins will also be compatible.  Different compilers actually make DLLs in different ways so a DLL compiled with minGW won’t work with the Maya binary because it was compiled with Visual Studio.    And since we are using VS to compile our plugin the base Qt libraries also need to be compiled using VS.  This is a once off this and I’ve found that VS is a much better IDE than Qt creator.  You can even still use Qt designer to create your UI!
 
Here’s what you’ll need to get this working on Windows:
·         Microsoft Visual Studio 2008 (Best to have the latest service packs etc)
·         Qt SDK version 4.5.3 source package.  You won’t find any links to this on the Qt site.  You can get it here:   http://get.qt.nokia.com/qt/source/qt-all-opensource-src-4.5.3.zip.  FYI if you want to browse the available source packages navigate to http://get.qt.nokia.com/qt/source
·         Qt Visual Studio Add-in.
·         About a day of time for Qt to compile.

And these are the exact steps I did to get Qt 4.5.3 compiled:
1.       Go to this blog post then read my next points BEFORE following the instructions: http://dcsoft.wordpress.com/2010/01/30/how-to-setup-qt-4-5-visual-studio-integration/  Huge props go out to DCSoft for writing this up.
2.       Skip the DOWNLOAD QT SOURCE CODE section. Just download the source package from the link above and unzip it here: c:\Qt\ 4.5.3-vc.  Ie after unzipping the files you should see a structure that has this path: C:\Qt\4.5.3-vc\src.
3.       In SET ENVIRONMENT VARIABLES step 1 you need to change the path: QTDIR = c:\qt\4.5.3-vc
4.       In BUILD VC++ VERSION OF QT substitute our Qt version everywhere ie replace 4.6.1-vc with 4.5.3-vc
5.       Wait about 8 hours or so for Qt to compile.
6.       In INSTALL VISUAL STUDIO ADD-IN step 3 replace 4.6.1-vc with 4.5.3-vc

Now we should have a fully functional version of Qt 4.5.3 complete with Creator and Designer binaries and VS project files for all the source examples.       

Here’s what I did to get an example widget plugin compiled and working in Maya 2011:
1.       Boot up Visual Studio and load this project:  C:\Qt\4.5.3-vc\examples\designer\worldtimeclockplugin\ worldtimeclockplugin.vcproj
2.       Change the configuration to Release and compile.  The compiled DLL will be here: C:\Qt\4.5.3-vc\plugins\designer\worldtimeclockplugin.dll
3.       Copy the DLL into the Maya folder:  C:\Program Files (x86)\Autodesk\Maya2011\qt-plugins\designer\
4.       Run this Python code:




And with a bit of luck you should see this: 
Awesomely the connections between the widget elements still work which means you can define quite a bit of functionality in QT Designer

Next up is investigating what needs to happen to compile a 64bit version.

1 comment:

  1. Have you figured out how to add menu actions in the toolbar? You can assign shortcuts to them and assign roles such as About and the such, but I saw no way to assign an actual command or trigger to them to load a new UI or widget window.

    ReplyDelete