PDA

View Full Version : Why does Qt use Private classes?



hyling
12th December 2006, 17:35
Hi,

Reading through the source I see a lot QClassPrivate and private data. I can understand the need to keep some of the function private but I don't understand why they went to the extent of creating a whole set of QClassPrivate classes... it makes the source more confusing to read.

Would someone enlighten me?
Thanks,
Hua-Ying

jacek
12th December 2006, 17:56
In short: to retain backward binary compatibility and still be able to introduce new features.

For longer answer check the links in this article (http://wiki.qtcentre.org/index.php?title=Private_Implementation).

Brandybuck
12th December 2006, 23:11
Slightly longer answer: to keep implementation details out of the API. A good example that Qt end users frequently run across are *.ui files. They create a Designer UI class for their layout, but don't want it in their API. So they create a "d-pointer" to the private implementation. Thus, one includes only "mydialog.h", and not "ui_mydialog.h" as well.

For additional info, see http://en.wikipedia.org/wiki/Opaque_pointer