Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Haven't used QT in a long time.Have they done away the with ’moc' and code generation? I found it extremely annoying that while we were using QT we weren't actually using c++, but a strange, language that looked like c++, but was actually further processed by qt to generate the c++ code. Are they done with that shebang?


The C++ that you write does not run through moc. It uses a few special macros, each of which either inserts something trivial (e.g. a virtual method declaration for Q_OBJECT) or nothing at all (e.g. "emit"). In another build step, moc scans for those macros and generates additional code accordingly. The features added by that generated code are super useful and are implemented in separate methods, i.e. code that does not somehow appear in the middle of your own.


Every C++ toolkit out there does something similar. Look at Herb Sutter's talk on metaclasses and see he says the same thing.


Without moc their is no signal slots and the handy stuff you get from plopping Q_OBJECT in your derived classes. So it's not going anywhere.


Can't they figure out a way to do that in pure c++ yet? In other words why does C++ lack reflection, and only seems to have a half baked RTTI? Perhaps the QT guys and other c++ application programmers didn't lobby C++ standards committee strongly enough for that?


Sure, but there's 1) a performance hit because things that can be done at compile-time currently, have to be done at runtime, and 2) syntactically verbose/cumbersome. They've decided that these things are not worth it to most people.

Besides, it still is C++: you can totally compile everything without the moc (although its probably not very useful to do so), since the extra keywords are just #defines.

I've personally never had any issues with the moc (but I did only ever use QtCreator/qmake, so...)


There is a possibility, but at the cost of uglier macros (since no reflection): https://woboq.com/blog/verdigris-qt-without-moc.html


There can't be reflection. C++ is compiled into machine code, it's a one way process.


There is a derivation of Qt named Copperspice that has removed the need for moc. See http://www.copperspice.com/



no


Not sure why you're being downvoted, since your answer is correct.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: