Access the Qt event loop in Maya

Maya uses a customized
version of Nokia’s Open Source Qt 4.7.1 framework (for Maya 2013).

If you want to use Qt
in your Maya plug-ins then you will have to use the same modified version as
Maya. Most of the Qt modified libs ship with the Maya distribution (located in $MAYA_LOCATION/lib). So in theory you would not need build the libraries yourself unless you need more. Then it will require that you build a local copy of Qt from the customized
source.

A copy of the
customized Qt 4.7.1 source is available from Autodesk’s Open Source web-site (http://www.autodesk.com/lgplsource) whereas the compressed file in the Maya distribution (the compressed file in the $MAYA_LOCATION/include/Qt folder) contains header file only. The WEB version includes text files
describing how to configure, build and install Qt for each platform supported by
Maya.

Qt4logo

I would also encourage you to read Kristine’s article on Qt, PyQt, and PySide before anything.

If you were writing
your own Qt application from scratch, you would need to create your own
QCoreApplication or QApplication instance to handle your application’s event
loop. When writing a Maya plug-in, you must instead use Maya’s own application
object which can be retrieved using Qt’s qApp macro.

#include <QtCore/QCoreApplication>
QCoreApplication *app = qApp;

From there you can use the Qt installEventFilter() method to trap all Application event.

void QObject::installEventFilter (QObject *filterObj)

In
standalone mode, Maya does only create a basic QCoreApplication. I.e. no
GUI, that is the most that Maya will do in batch mode. But Maya will nicely use any Qt application already running, so you need to create your
own Qt appplication before initializing Maya standalone libraries and then you can access the event loop as usual.

Logo_faq_tiny_50_pyqt


Pyside-rounded-corners
Note on PySide – while you will need to compile the PySide libraries yourself before using it, PySide solution is not different from what was written in C++ above. Same approach / same code almost. Before you ask the question – why Autodesk does not provide the compiled PySide libraries? To keep it simple, that is because of a legal reason.
Pyqt Same for PyQt, the code would not be much different, but you will still need to compile the PyQt libraries yourself.

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading