I am trying to create a Maya C++ Plugin With Qt.
Used CMake to get work with Visual Studio.
My plugin works fine with general Qt components.
However if there are any Q_OBJECT macros in files, building the project gives linking errors about QMetaObject, etc…
So I read same errors over the internet, everyone seem to agree it is about the customized moc.exe but give no details for the solution.
How can I handle with Maya’s customized moc.exe with CMake ?
C++, Qt Q_OBJECT Problem With CMake
Yes I used that but some files are missing, even Qt Designer cannot open itself succesfully in the customized version, shame.
I tried the whole day and so many different options, let me summarize.
When I try these cmake config files, it gives an error about QtCore5d.dll, the last “d” is for Debug, I tried to remove Debug profile but same error again, there is no QtCore5d.dll anywhere, even in Autodesk’s customized Qt 5.6.1 which seems to be 656MB complete package.
C:\Program Files\Autodesk\Maya2017\cmake
Profiles in this folder give same problem above. (It seems to be same files, so why these are duplicated anyway)
C:\Program Files\Autodesk\Maya2017\lib\cmake
CMake files of Autodesk’s customized Qt 5.6.1 gives another error about platform plugins, by the way the folder structure is not compatible with cmake structure, I changed names of folders to make it compatible, I also copied missing files and folder from Autodesk Maya itself, made some progress but again there is one final error about QtRender2d.dll(something like that) which cannot be found anywhere in my computer.
I tried the official FindQt5.cmake package of KDE and another error because Autodesk did not seem to follow any of standarts neither qt or cmake, their distributed files seems to only work with their Autodesk Visual Studio 2012 wizard, there are no find*.cmake packages, I am telling you, even Qt Designer is not working because of missing dlls, it was supposed to be a complete package.
I tried to find an option to change cmake’s automoc by a customized version but again, fail related of same errors above.
Anyway finally I managed by compiling ui files and moc files one by one manually by my hands.
Compiled ui files to header files by the official Qt Creator and compiled moc files by Autodesk’s moc.exe and included them at the end of header files then it seems to work.

However if any of you guys know anything about how to automate this, I will be grateful because whenever I change the code, I have to recompile moc files again.
Thank you.
Alright I have found the way after a few days of struggling
We have to download modified version of Autodesk Qt if you want to use QObject Macro, that is for certain. (Qt 5.6.1 package for the 2017 version)
http://www.autodesk.com/company/legal-notices-trademarks/open-source-distribution
You can extract it anywhere you wish.
Then in CMake we have to include inc folder, we have to link libs folder of downloaded file and finally this piece of code takes care moc, uic, rcc processes for Windows. (You have to modity “Qt Bin Path” to bin folder of downloaded file)
set(QT_VERSION_MAJOR 5)
find_program(QT_MOC_EXECUTABLE moc.exe PATH "Qt Bin Path"))
add_executable(Qt5::moc IMPORTED)
set_target_properties(Qt5::moc PROPERTIES IMPORTED_LOCATION ${QT_MOC_EXECUTABLE})
set(CMAKE_AUTOMOC TRUE)
find_program(QT_UIC_EXECUTABLE uic.exe PATH "Qt Bin Path"))
add_executable(Qt5::uic IMPORTED)
set_target_properties(Qt5::uic PROPERTIES IMPORTED_LOCATION ${QT_UIC_EXECUTABLE})
set(CMAKE_AUTOUIC TRUE)
find_program(QT_RCC_EXECUTABLE rcc.exe PATH "Qt Bin Path"))
add_executable(Qt5::rcc IMPORTED)
set_target_properties(Qt5::rcc PROPERTIES IMPORTED_LOCATION ${QT_RCC_EXECUTABLE})
set(CMAKE_AUTORCC TRUE)
I have implemented the full CMake for Maya and Qt to Windows, Linux and Mac, you can find it in the next version of ToolSeq UD.
https://canerozdemirportfolio.wordpress.com/script/toolseq-ud-autodesk-maya/