Maya Qt toolchain in Qt Creator

Okay, so I’m just starting out with programming Maya plugins in C++. I’m using Qt Creator as my IDE, and as far as getting a working plugin into Maya is concerned, all is well. However, as soon as I try to add in any Qt UI elements, I get a bunch of undefined symbol linker errors. I’m working on the Mac with Maya 2016. I’m 99% sure it’s a toolchain problem, so I won’t waste your time with source code. The actual output is over 2000 lines, so I’m not going to try to paste the whole thing here, but here’s the first few lines, including the g++ invocation:

g++ -headerpad_max_install_names -arch x86_64 -all_load -Xarch_x86_64 -mmacosx-version-min=10.5 -o MayaTest.bundle mayatest.o mayatestgui.o moc_mayatestgui.o -L/Library/Frameworks -bundle -L/Users/kmiller/CPPProjects/TryNumber3/MayaTest/…/…/…/…/…/Applications/Autodesk/maya2016/lib/ -lQtUiTools -L/Users/kmiller/CPPProjects/TryNumber3/MayaTest/…/…/…/…/…/Applications/Autodesk/maya2016/Maya.app/Contents/MacOS -lOpenMaya -lFoundation
Undefined symbols for architecture x86_64:
“qFreeAligned(void*)”, referenced from:
QFormInternal::QAbstractFormBuilder::createDom(QLayout*, QFormInternal::DomLayout*, QFormInternal::DomWidget*) in libQtUiTools.a(abstractformbuilder.o)
QFormInternal::QAbstractFormBuilder::saveTreeWidgetExtraInfo(QTreeWidget*, QFormInternal::DomWidget*, QFormInternal::DomWidget*) in libQtUiTools.a(abstractformbuilder.o)

and so forth. Like I said, over 2000 lines worth.

I’ve removed the core and gui elements from the QT variable, because those are supposed to be referenced in the INCLUDEPATH variable later. As a matter of fact, if I comment that line out, it compiles, but then it crashes Maya when I load it - probably because Maya uses a modified set of libraries and headers for Qt. Here’s what I’m using for my .pro:

TARGET = MayaTest
CONFIG += staticlib
DEFINES += REQUIRE_IOSTREAM _BOOL

QT -= core gui

# stuff for me to edit
SOURCES += mayatest.cpp
mayatestgui.cpp

HEADERS += mayatest.h
mayatestgui.h

FORMS += mayatestgui.ui

# add in the dylib bundle, but remove the dynamic lib
macx: LIBS += -bundle
mac: LIBS -= -dynamiclib
macx: DEFINES += OSMac_

# project definitions for the mac
macx: TARGET = MayaTest.bundle
macx: LIBS += -L$$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/lib/ -lQtUiTools
macx: LIBS += -L$$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/Maya.app/Contents/MacOS -lOpenMaya -lFoundation
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt/QtCore
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt/QtGui
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include
macx: DEPENDPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include

# remove the app bundle config, since we’re making a lib
macx: CONFIG -= app_bundle

# dependencies for the Qt libraries
macx: PRE_TARGETDEPS += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/lib/libQtUiTools.a

So as far as I can tell, I have all of the correct libraries referenced, but apparently, I’m missing something. I did a search through the maya2016 folder for any other libraries, but the only ones I see are for specific plugins like Bifröst and Alembic.

Now, I’m not married to Qt Creator, so if there’s a better way of going around this, please do share. I’d rather not use Xcode if I can avoid it, though, and obviously Visual Studio is out of the question on the Mac.

Any guidance? I want to do the entire plugin in C++, without any elements in a MEL or Python script. This is mostly just to learn how to do it.

EDIT: Currently, I have Qt using the libraries that cause Maya to crash. These are libraries that I built from sources I downloaded from Autodesk’s website, and they’re for Maya 2016, which is what I’m using, so they have to be the right libraries. If I run Maya from the command line, I get a stack trace ending in

QWidget: Must construct a QApplication before a QPaintDevice

However, I’m not even using any GUI elements right now - I’m focusing on getting it to run without crashing. I’m not even referencing any Qt elements anywhere in my code, and I don’t even have the includes, so I don’t know why it’s even touching Qt at the moment.

Also in that stack trace, I get a number of messages about two different libraries:

objc[10383]: Class QNSApplication is implemented in both /Applications/Autodesk/maya2016/Maya.app/Contents/MacOS/QtGui and /Library/Frameworks/QtGui.framework/Versions/4/QtGui. One of the two will be used. Which one is undefined.

I have a feeling this may be part of it, if not the whole thing, but I have no idea how to tell it which library to use.

Any help would be appreciated!

Thanks!

I took about 2ish weeks to build out QT for Maya, not a fun task. But I don’t see, are you using QMake? Qt Creator needs to be built out using QMake .pro file (If I remember correctly) I don’t know exactly if it does on a Mac.

How I am building using ‘QMake.bat’ (Windows):

cd /d %~dp0
rmdir /s /q autogen
del QT_UI.h
"%DEVKIT_LOCATION%\devkit\bin\qmake" mayaPlugin.pro
nmake release
echo D | xcopy /y /s release autogen
rmdir /s /q release
rmdir /s /q debug
PAUSE

Do you have any moc files generated? can I see one?

I just installed Qt Creator from the installer on the Qt website. I did do a build of the Qt libraries (version 4.8.6, which is what Autodesk says is required for 2016), and pointed Qt Creator at those libraries, but I didn’t build the IDE itself. It took an hour or so to compile, and qmake was one of the binaries it produced.

I’m considering switching over to a Windows platform, since Apple is steadfastly refusing to use real video cards in their computers. Any links to get me started if I go that route? Don’t go too much out of your way for it - I’m not much of a fan of Windows either, so I’m still vacillating on that.

Hey, thanks for the help - I’m working on my master’s, and this is part of my thesis, so there’s a lot riding on it. Much appreciated!

Congrats man! This is a good project to learn a ton about both Maya and QT.

For myself I am a Windows user so I don’t know if it would suit you better to switch, I think creating the plugin is almost identical. (Unlike Photoshops Plugin where I had to build a resource file for Windows).
But the GPU argument is always valid when dealing with Apple so I say switch anyways :smiling_imp:

Was a good resource: http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_GUID_13434252_F0BF_4AC0_B47B_09BD626B0881_htm

When you say the IDE are you talking about [QT Creator, designer, or qmake]?

Designer and Qmake (should come as a program / command on your computer)

Designer generates moc files (The UI) of your application., it’s not needed because you can build out your moc files with CLI (And I’m old fashioned, I like to build all my UI’s by code rather than dragging and dropping elements)

I think Designer is just the interface drag ‘n’ drop deal. Creator is the actual IDE that you can compile code from. At least, I never found a way to compile code from Designer. When I did the compile, qmake is one of the things that was produced, along with the libraries. What I’ve been doing as a workaround is to build the interface in Designer, then load it and assign callbacks via MGlobal::executeCommand(). It does all of that in the initializePlugin() function, and then the callback basically calls the command with arguments based on which button was clicked. It works, but it does have its drawbacks.

And as far as Apple is concerned, I love the OS, the interface, and the security, but good grief, if they can’t give me the hardware I need, then frankly, I can’t use their platform. The main reason I’m thinking about switching to Windows is that I get the impression that most of the studios are on Windows, so I need to be prepared to work in that environment. Funny thing is, up until 2009, I was a Windows guy, then switched to Mac, loved it, and then Apple started making boneheaded design decisions, so now I’m considering going back.

And ya, I’ve done interface design both ways. While I don’t think there’s anything wrong with drag ‘n’ drop, I do think it’s a good idea to know what’s going on in the code. I recently coded an autorigger entirely in MEL including the interface, which was quite a trip. It’s one of the reasons I’m in C++ now. LOL

If you use python, (And I highly recommend it, seeing how Mel is a single use language and it’s Disgusting) you can register the plugin commands http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_Command_plugins_Registering_commands_htm and call it directly using the ‘cmds’ module (namespace).
Just call plugin.registerCommand() in the init function.

For instance:

   #myScript.py 
   cmds.uicreator(myArgument, '-LoadUI')

   //MyPlugin.cpp
   class UICreator : public MPxCommand
    {
    public:
      UICreator() {};

      MStatus doIt(const MArgList& args);
    }

It’s a little cleaner and you’re using a language that you can work with, [Houdini, Maya, Blender, Cinema 4D, GIMP] to name a few use python as their embedded scripting languages.

The main reason I’m thinking about switching to Windows is that I get the impression that most of the studios are on Windows,

I’ve worked at big and small game studios and the only place I have seen Apple is at mobile app studios.

Oh god, I’m so sorry,

Ya, I’ve been trying to avoid Python. I’ve worked with it for a variety of other applications, and while I’m capable of using it, I’m not exactly fond of it. Doing the autorigger in MEL was hard, but it was a good learning experience. I’ve coded in assmbler before, so I’m sort of prepared for the worst. I got a good feel for how MEL works and why it is what it is, and why I don’t want to use it any more than Python. : ) It’s good for quick and dirty scripts that I can do in a few lines, but anything significant, I want to do in C++. Incidentally, if I take out all of the references to Qt, including the project file and the make file and just completely sanitize the entire project of Qt, then the plugin works great, albeit without an interface. I even had it constructing entire skeletons.

All of that said, you’re kind of persuading me to switch over to doing the project in a Windows environment instead. One of my colleagues, who’s a self-proclaimed “equal opportunity operating system hater”, says that doing development in a Windows environment is more forgiving, whereas doing any kind of programming in a Unix-based environment forces you to do everything by the book. The example he used was that in Windows, if your project has a memory leak, it will work just fine until the OS runs out of memory and it crashes. In Linux or MacOS, it will refuse to run and make you fix it.

Anyway, he and I were working on it yesterday, and we pulled some of the example code again and recompiled it, with the same results. Maya loads up, you check the box in the Plugin Manager, and then if you click anywhere in the script editor or in the MEL command window, it crashes. If you run Maya from the command line and do all of that, then it gives you the stack trace I originally posted. So I’m pretty well convinced that it’s not in my code, but somewhere either in my Qt project file or in a make file somewhere. I might have a library in a wrong place, or maybe referencing something I shouldn’t be, or something. Just not sure what.

This looks like it’s linking the QtGui library that ships with Maya, and another one in your Library folder. Which is probably confusing the plugin because it doesn’t know which library to be pulling symbols from.
Not sure if this is still the case, but the last time I had to compile PySide or PyQt4 myself, I had to use the autodesk supplied version of Qt, and compile from that, because I think they made local modifications to the project.

Correct. I actually did compile the one from Autodesk. The thing is, both of those locations contain the exact same libraries - both compiled by me. I wasn’t sure where they were supposed to go when I was setting up, so I put them in both places. I didn’t install the devkit initially when I installed Maya, so I downloaded it and put it there, and then later (when it wasn’t working) replaced the Qt libraries with the ones I compiled. Would that still cause issues, since it wouldn’t matter which one it pulled?

Just in case, is there any way I would go about eliminating one of those locations for Maya to look, without changing it system-wide? And if I were to send it off to someone else to use, how would I make sure it would pick the right library?

Honestly not sure how to adjust search paths on osx.

But basically you want to make sure you’re headers, libs, and binaries are located first on their various search paths, which should be INCLUDE (headers), LIB (libs), and PATH (binaries).
Any changes you make to this during the build sessions shouldn’t impact the rest of the system.

I think you may have hit it right there. Changing my build paths don’t change my runtime paths. So that particular message might be caused by an incorrect path on my host operating system. That also means that it shouldn’t replicate when I send it off to a user. I’m going to try running the plugin on another computer to see what happens. I haven’t done that yet because it’s not easy to find another Mac with Maya on it. Plenty of Macs, just not with Maya. : P

I think I am going to switch over to Windows for my project, though. Too many people are bailing out on Apple.

That might be your problem! That’s looking for a Windows item, so it’s not going to find it on Mac OSX.
I have Qt Creator running fine on windows. And that’s been to use Creator’s plugin compiling capabilities.
A lot of it comes down to build settings.
You have to make sure that you have a lot of things hooked up!

Check out the settings that you have in your .pro file.
Maybe by default, your project is pointing to Windows assets/folders.

I have certainly successfully used Designer with Mac Maya.
All this stuff works, it’s just majorly fiddly…

Actually, I solved that part of it by taking out the Core and GUI elements from the Qt variable. Now the problem is that it’s crashing when I get it into Maya. As stated in an earlier post, the errors that I’m getting now are

and

So I think the issue is somewhere on my host system, not in my make file or project file or code. I’m going to move this over to another Mac to see if I can get it going. If so, then I know where the problem is.

Thanks for the attempt, though. You are right about one thing - it’s majorly fiddly. I think if I can get this going, I’ll write a tutorial and post it here.

Just want to toss my two cents back into the mix, we’re actually updating to 2018 for the team and there are a lot of headers (mostly with the widget classes) that are going to have to be converted / functions in our plugin that need to be changed. IF you’re set with maya 2016 continue on with it but if you’re looking to update to 2018+ I would suggest creating everything now with 2018 because you will have to convert to Qt5.

Good luck ArtGeek!

if you’re looking to update to 2018+ I would suggest creating everything now with 2018 because you will have to convert to Qt5.

Good to know. Thanks!

Hey @ArtGeek Did you ever solve your issue? I’m just updating my Photoshop to Qt 5.0 and was reminded about this convo.

I actually moved on to another project (not entirely by choice). Unfortunately, I’m not going to be able to do anything with this until after I get my thesis done. That also means that by then, we’ll all be programming for Maya 2018, which means that anything I’ve figured out is likely to be irrelevant, I’m afraid.

It was still a good experience - I learned a lot about C++ and makefiles in particular. Eventually, I’ll get back to trying to do this, but for now, other things take priority.