Search code examples
c++qt32bit-64bitmoc

Qt moc.exe - difference between 32 and 64-Bit version?


I am trying to find out what the difference is between the moc.exe (Qt meta object compiler) in the respective 32-bit and the 64-bit subfolder of Qt5.

Does it make any difference if I let my application with 64-Bit target architecture be built (and processed) by the 32-Bit or 64-Bit moc.exe version?

I couldn't find any info on this. If anybody has a clue or an idea what the difference is (beside being compiled for the according architecture and having a different file size of course) or if this makes a difference at all (as it only generates cpp files) I'd be very interested to know.

Thanks in advance Samir


Solution

  • Does it make any difference if I let my application with 64-Bit target architecture be built (and processed) by the 32-Bit or 64-Bit moc.exe version?

    Yes. Such mixing-and-matching is not supported. It might work, but it might break since nobody tests it to ensure that it works. Qt has an extensive test suite that runs in the continuous integration process. Something like this being untested is a big hint that you're on your own if you depend on it. Don't complain if you run into strange runtime bugs. Don't do it.

    what the difference is

    Anything and everything. All that Qt guarantees as a contract with you is that the moc output from a previous binary-compatible Qt version retains forward binary compatibility. E.g. if you have moc output from Qt 5.7, and you build a shared binary of your application, then replace Qt with binary-compatible 5.8, the old moc output is valid and Qt 5.8 knows how to use it safely. That's all.

    Since, obviously, 32- and 64-bit Qt versions are not binary-compatible, you should not expect the moc output to be either. If it happens to be, it's a coincidence and nothing in the design guarantees it. It can break at any time.

    You shouldn't be facing this problem since qmake/qbs/cmake will use the correct moc for you. It seems like perhaps you're trying to preprocess the sources using moc so that further use of moc won't be necessary while building the project. This strategy will not work. You need to learn how to leverage the build tools to build your project using the code generators it needs.

    moc is not the only build tool provided by Qt you might end up using in a Qt-based project. Furthermore, projects of any significant size should be using many other code generators as well to make you more productive. Avoiding code generation as a policy is counter-productive. As in: it will cost you more.