For the Qt plug-ins, these are the recent changes made that are not reflected in the documentation but are important to know.
Using the qmake executable and its qt.conf file from the devkit archive is recommended. The use of this qt.conf file uses MAYA_LOCATION and DEVKIT_LOCATION to locate the expected header/library files. Therefore, users must set both environment variables before building the samples.
DEVKIT_LOCATION should point to the directory where the devkit include, mkspecs, cmake directories are located.
After running qmake, a makefile is created and named per pluigin with the .mak extension.
A top level Makefile.qt is provided that can be used to build the default Qt plug-ins.
For more details (exactly what will change in the API Guide), please see the text in red below.
Building the plug-in
<image007.png>
As noted at the start of this section, Maya ships with customized versions of the Qt libraries and header files. It is important to ensure that the directory containing Maya's version of the headers appears in your include path before those which you may have in a separate Qt installation elsewhere on your system, and that the directory containing Maya's version of the libraries appears in your library path before any others.
It is important to use the version of qmake that is provided with the Maya Developer Kit. After running qmake, a makefile is generated that can be used to build the Qt plug-in.
To build the Qt plug-ins provided with the Maya Developer Kit, follow these steps:
- Use the following Qt archives from the Maya installation, and extract them in place.
You can also obtain the same files from the Maya Developer Kit:
- include/qt-5.6.1-include.tar.gz
- mkspecs/qt-5.6.1-mkspecs.tar.gz
- lib/cmake/qt-5.6.1-cmake.tar.gz
- Obtain the plug-in example files from the Maya Developer Kit; for example, the helixQtCmd.cpp, helixQtCmd.h, and helixQtCmd.pro files for the helixQtCmd example.
- Create a helixQtCmd directory.
Copy the aforementioned helixQtCmd.* files to the helixQtCmd directory. - Copy the qtconfig file (from the devkit/plug-ins directory) to the helixQtCmd directory.
- Set your MAYA_LOCATION environment variable to point to your Maya installation, and the DEVKIT_LOCATION environment variable to point to the directory where the devkit include, mkspecs, cmake directories are located.
- Navigate to the helixQtCmd directory.
- Run the version of qmake that is provided with the Maya Developer Kit archive.
$DEVKIT_LOCATION/devkit/bin/qmake helixQtCmd.pro
A makefile is created as a result and named per plug-in with .mak extension.
make –f helixQtCmd.mak
nmake /f helixQtCmd.mak
A top level Makefile.qt is provided that can be used to build the default Qt plug-ins.
- Run make using the generated Makefile as follows:
- Linux: make –f Makefile.qt
- Mac OS X: make –f Makefile.qt
- Windows: nmake /f Makefile.qt
NOTE:
Makefile requires a qmake project file ending with the extension .pro. Shown below is helixQtCmd.pro, the project file provided in the Developer Kit for the helixQtCmd plug-in. It provides a good example of the straightforward nature of the majority of project files.
include(qtconfig)TARGET = helixQtCmdHEADERS += helixQtCmd.hSOURCES += helixQtCmd.cppLIBS += -lOpenMayaUI
The TARGET setting contains the name of the plug-in, excluding its platform-specific extension.
The HEADERS setting contains a space-separated list of all the header files which are part of the plug-in.
The SOURCES setting contains a space-separated list of all the source files which are part of the plug-in.
By default, the plug-in is automatically linked to Maya's Foundation and OpenMaya libraries. If the plug-in needs other libraries, then they should be added to the LIBS setting. Library names should be preceded by '-l' while additional library directories should be specified using '-L'. For example:
LIBS += -L/usr/local/lib -lxml
For more complex needs, please refer to Qt's qmake documentation.
Maya uses a customized version of Digia's Qt framework and ships with its own versions of all the libraries and header files you need to use Qt in your plug-ins. On Linux and OS X the libraries are in Maya's lib directory. On Windows the link libraries are in Maya's lib folder and the DLLs are in Maya's bin folder. On all platforms the header files are shipped as a compressed archive (e.g. qt-5.6.1-include.tar.gz) in the include directory of your Developer Kit installation. Before doing any Qt plug-in work, uncompress the archive into a directory where you have write permission and be sure to include that directory ahead of any others in your include path.
You can create custom UI for Maya using Qt Designer. For Windows and Linux users, Qt Designer is installed with Maya. For Mac OS X users, you can find Qt Designer directly at the Qt Development Tools website; or, you can build Qt from source.
To obtain Qt Designer, you can also install Digia's standard version of Qt on your system or download a copy of the customized Qt source from Autodesk's Open Source web-site (http://www.autodesk.com/lgplsource) and building the tools yourself. If you choose the latter option the download includes text files describing how to configure, build and install Qt for each platform supported by Maya.
Hi Cyrille - I'm wondering if you've had any luck building pyqt for maya2017 yet? Your notes for prior versions of maya are indispensible! Looking forward to seeing this round when you get time. Cheers - James.
Posted by: James Rowell | August 02, 2016 at 08:35 AM
Hey!
I was working on a maya 2016 and when 2017 came out I began porting my work to 2017 due to the fact that it uses qt5 which has built in features that I need.
Straightaway I ran into a lot of issues that come from deep inside qt itself (e.g. QString::toStdString function causing crashes,
Workaround: use call .toLocal8Bit().constData() instead) .
Another issue is with the qt examples, they worked fine for qt4 but there are some breaking changes that make them bad reference point for develops e.g.:
Using QPointer to store the pointer to the plugin window will cause memory access violation due to major change in QPointer implementation in qt5, the following is from Qt docs:
Note that Qt 5 introduces a slight change in behavior when using QPointer.
"When using QPointer on a QWidget (or a subclass of QWidget), previously the QPointer would be cleared by the QWidget destructor. Now, the QPointer is cleared by the QObject destructor (since this is when QWeakPointer objects are cleared). Any QPointers tracking a widget will NOT be cleared before the QWidget destructor destroys the children for the widget being tracked."
the workaround so far is to use QSharedPointer.
Posted by: Leon Rosengarten | August 03, 2016 at 05:37 AM