Fun and Scary Code from Qt and KDE
These 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; } sleep(3); delete splash; app.exec();
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 ) r--; return r; }
Writing code that builds from Qt 1 and Qt 2 (not from KDE developers . . .)
if (!strncmp((LPCSTR)Destination #ifdef QT_20 .latin1() #endif , "file:", 5)) { GoItem((LPCSTR) Destination #ifdef QT_20 .latin1() #endif + 5); ...
Found in koffice/filters/kocrypt/kocryptimport.cc, 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/kspread_cell.cc (KOffice 1.1), trying to save a date
tmp=tmp.setNum(m_Validity->dateMin.year())+"/"+ tmp.setNum(m_Validity->dateMin.month())+"/"+ tmp.setNum(m_Validity->dateMin.day());
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 https://github.com/KDAB/GammaRay/blob/master/probe/entry_unix.cpp#L44)
static HitMeBabyOneMoreTime britney;
Happy Halloween, folks.
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.
I don’t see any code snippet from NeoChat, I guess it means our code is perfect!
I didn’t look into current code to avoid vexing anyone 🙂