Skip to content

Fun and Scary Code from Qt and KDE

code snippetsThese are some really cool or obfuscated code snippets for your amusement. We didn’t want to rate them, so the order doesn’t mean anything at all 🙂

Just to make sure that there’s no misunderstanding: This code really is/was in the Qt or KDE repositories.

From Kivio, main.cpp

  if (!app.start()) {
      delete splash;
      return 1;
  delete splash;

From Qt 2.2.1 (src/canvas/qcanvas.cpp)

static int gcd(int a, int b)
  // ### Should use good method, but not speed critical.
  int r = QMIN(a,b);
  while ( a%r || b%r )
  return r;

Writing code that builds from Qt 1 and Qt 2 (not from KDE developers . . .)

if (!strncmp((LPCSTR)Destination
#ifdef QT_20
    , "file:", 5))
    GoItem((LPCSTR) Destination
#ifdef QT_20
        + 5);

Found in koffice/filters/kocrypt/, not really code, but still funny

// OK. Get this. I'm not going to add 4 lines of code to this thing and
// nest it in another [infinite] loop just so someone can feel warm and
// fuzzy because they found a complicated way to avoid using a perfectly
// fine goto. This is my code and I like the goto just the way it is.
// Deal with it.

Found in qt/src/gui/kernel/qlayoutengine.cpp – also “just” a comment

Do a trial distribution and calculate how much it is off.
If there are more deficit pixels than surplus pixels, give
the minimum size items what they need, and repeat.
Otherwise give to the maximum size items, and repeat.

I have a wonderful mathematical proof for the correctness
of this principle, but unfortunately this comment is too
small to contain it.

From qt/plugins/src/imageformats/jpeg (3.0 beta 4)

if ( name.lower() != "JPEG" )

From kdebase/kate/view/kateviewdialog.cpp (KDE 2.2) (m_search is a QComboBox)

((QLineEdit *) (m_search->children()->getFirst()))->selectAll();

From koffice/kspread/ (KOffice 1.1), trying to save a date


From Qt 3’s qlabel.cpp

void QLabel::buddyDied() // I can't remember if I cried.

From kdepim/messageviewer/objecttreeparser.h until the end of KDE 4

* The origin and purpose of this function is unknown, the ancient wisdom about it got lost during
* the centuries.
* Historicans believe that the intent of the function is to return the raw body of the mail,
* i.e. no charset decoding has been done yet. Sometimes CTE decoding has been done, sometimes
* not. For encrypted parts, this returns the content of the decrypted part. For a mail with
* multiple MIME parts, the results are conecated together. Not all parts are included in this.
* Although conecating multiple undecoded body parts with potentially different CTEs together might
* not seem to make any sense in these modern times, it is assumed that initially this function
* performed quite well, but the ancient scrolls got damaged with the ravages of time
* and were re-written multiple times.
* Do not use. Use plainTextContent() and htmlContent() instead.
MESSAGEVIEWER_DEPRECATED_EXPORT QByteArray rawDecryptedBody() const<br>

And finally, found in KDAB’s very own GammaRay (from

static HitMeBabyOneMoreTime britney;

Happy Halloween, folks.

About KDAB

If you like this article and want to read similar material, consider subscribing via our RSS feed.

Subscribe to KDAB TV for similar informative short video content.

KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us.

Categories: KDAB on Qt / Technical

2 thoughts on “Fun and Scary Code from Qt and KDE”

Leave a Reply

Your email address will not be published. Required fields are marked *