PDA

View Full Version : Qt Source Macros



cwalsh
8th January 2006, 19:12
In the Qt GUI sources, what do the macros like Q_D & Q_Q do?

jacek
8th January 2006, 19:27
#define Q_D(Class) Class##Private * const d = d_func()
#define Q_Q(Class) Class * const q = q_func()
First one obtains a "d-pointer" that points to the private part of the implementation.

From "Data Sharing with Class" by Jasmin Blanchette (http://doc.trolltech.com/qq/qq02-data-sharing-with-class.html)
The term "d-pointer" was coined by Arnt Gulbrandsen and later adopted by Qt and KDE programmers. It is called "Pimpl" (Pointer to implementation) in the book Exceptional C++, and "Cheshire Cat" in Design Patterns.

The second one obtains a pointer to the public part of the implemention.