https://www.kdab.com/fun-and-scary-code-from-qt-and-kde/ Skip to content x How can we help you? Thanks for your interest in KDAB. Please write your message here and we'll get back to you as soon as possible. Name: * [ ] E-Mail: * [ ] Company: [ ] Phone: [ ] [ ] [ ] [ ] [ ] Message: * [ ] KDAB is committed to ensuring that your privacy is protected. * Only the above data is collected about you when you fill out this form. * The data will be stored securely. * The data will only be used to contact you about possible business together. * If we do not engage in business within 3 years, your personal data will be erased from our systems. * If you wish for us to erase it earlier, email us at info@kdab.com For more information about our Privacy Policy, please read https://www.kdab.com/about/kdab-privacy-policy/ [ ]* I have read and agree to the terms above. [ ] Yes, sign me up for the KDAB newsletter [Send] x Contact us Germany - KDAB (Deutschland) GmbH Reuchlinstrasse 10-11, 10553 Berlin +49 30 5213 254 70 +49 30 5213 254 99 info-de@kdab.com Other countries US: +1.866.777.5322 FR: +33 4 90 84 08 53 UK: +44 1625 809908 JP: +81 70 4001 0910 Full list all countries x Contact us Name[ ] E-Mail[ ] Company[ ] E-Mail[ ] [ ] [ ] [ ] Message[ ] Please attach your CV (PDF only) [ ] captcha [ ] [Send request] * Services + Projects o Code Migration o Modernization o Development o Consulting & Architecture o Mentoring & Support + Workshops o Code Migration & Modernization o Architecture o Profiling & Performance o Testing & Refactoring o Agile Development + Design Services + Training: On-Site o Qt Training # Qt Widgets for the Desktop # Qt/QML Training # Qt/QML for Embedded Training # Advanced QML Training # Advanced Qt Widgets Training o C++ Training # Modern C++: Introduction # Modern C++: C++11 / C++14 / C++17 o Modern OpenGL # Modern OpenGL: Introduction # Modern OpenGL: Advanced Rendering and Effects # Modern OpenGL: Advanced Pipeline and Performance o Qt 3D Training o Debugging and Profiling # Debugging and Profiling Qt apps on Windows # Debugging and Profiling Qt apps on Linux # Debugging and Profiling C++ apps on Windows # Debugging and Profiling C++ apps on Linux o Other On-site Courses # In-Depth Multithreading # Introduction to CMake # Git Training # Qt with Squish Training # Qt 3D Studio training o Training Facilities o KDAB Trainers o Testimonials o Terms/Conditions + Training: Scheduled o Qt Training # Qt Widgets for the Desktop # Qt/QML Training # QML for Embedded Training # Advanced QML Training # Advanced Qt Widgets Training # Model/View o Modern C++ # Modern C++: C++11 / C++14 / C++17 # Modern C++: Introduction o Modern OpenGL # Modern OpenGL: Introduction # Modern OpenGL: Advanced Rendering & Effects # Modern OpenGL: Advanced Pipeline & Performance o Qt 3D Training o Debugging and Profiling Courses # Debugging and Profiling Qt apps on Windows # Debugging and Profiling Qt apps on Linux # Debugging and Profiling C++ apps on Windows # Debugging and Profiling C++ apps on Linux o In-Depth Multithreading o Introduction to CMake o Testing Qt with Squish o Qt 3D Studio training o Training Schedule o Training Facilities o KDAB Trainers o Testimonials o Terms/Conditions * Expertise + Qt / QML o Qt 3D o Qt on Android o Qt on QNX Neutrino RTOS o Qt on Windows Embedded CE o Qt Tools o Is Qt Right for Your Project? + C++ o C++ Latest Standards o C++ Tools o C++ Training # Modern C++: Introduction # Modern C++: C++11 / C++14 / C++17 + 3D / OpenGL o OpenGL o KUESA 3D Studio o KUESA glTF Library o Qt 3D o Vulkan * Platforms + Android + Linux + Web integration + QNX + Windows Embedded + Mobile iOS/Android + Windows + macOS + Unix / X11 (Motif) * Resources + Blogs + KDAB TV o News o Academy # Introduction to Qt/QML # Qt Widgets and more... # Kuesa 3D # GammaRay # Presentations o Showcases o Events # Demos o Archive + KDAB Monthly Digest + Content Library Search + Whitepapers, Brochures & Articles + Success Stories + Conferences o Qt Embedded Days o Qt Desktop Days o Qt World Summit # Qt World Summit '20 # Qt World Summit '19 # Qt World Summit '18 # Qt World Summit '17 # Qt World Summit '16 # Qt World Summit '15 o QtCon 2016 o Qt Developer Days # Qt Developer Days 2014 # Qt Developer Days 2013 # Qt Developer Days 2012 + Newsletter + Events + Qt Tools + Qt and CMake resources + Qt Creator Card * [ ] * * * About us + Contact + Customers & Industries + ISO 9001 Certified + Partners + Mission + Working at KDAB + KDAB France + KDAB Japan + Terms and Conditions + Privacy Policy & Cookies Qt/QML C++ 3D/OpenGL Qt/QML C++ 3D/OpenGL Fun and Scary Code from Qt and KDE # 22.10.2021 # David Faure # 2 comments FacebookTwitterLinkedInEmail 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; } 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
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. 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. FacebookTwitterLinkedInEmail Categories: KDAB on Qt / Technical 2 thoughts on "Fun and Scary Code from Qt and KDE" 1. [2646] # Carl Schwan # 22.10.2021 # 12:31 pm I don't see any code snippet from NeoChat, I guess it means our code is perfect! Reply 1. David Faure # David Faure # 22.10.2021 # 12:37 pm I didn't look into current code to avoid vexing anyone Reply Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment [ ] Name * [ ] E-Mail * [ ] [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] Improve your programming skills Book a scheduled KDAB training! Boost team productivity Book an on-site training! Access KDAB's expertise Book a workshop! The KDAB Group is the global No.1 software consultancy for Qt, C++ and OpenGL applications across desktop, embedded and mobile platforms * About us + Contact + Customers & Industries + ISO 9001 Certified + Partners + Mission + Working at KDAB + KDAB France + KDAB Japan + Terms and Conditions + Privacy Policy & Cookies * Services + Projects + Workshops + Design Services + Training: On-Site + Training: Scheduled * Expertise + Qt / QML + C++ + 3D / OpenGL * Platforms + Android + Linux + Web integration + QNX + Windows Embedded + Mobile iOS/Android + Windows + macOS + Unix / X11 (Motif) * Resources + Blogs + KDAB TV + KDAB Monthly Digest + Content Library Search + Whitepapers, Brochures & Articles + Success Stories + Conferences + Newsletter + Events + Qt Tools + Qt and CMake resources + Qt Creator Card Contact us DE: +49 30 5213 254 70 US: +1.866.777.5322 FR: +33 4 90 84 08 53 UK: +44 1625 809908 JP: +81 70 4001 0910 Full list, all countries * * [New-QAS-LO] Manage cookie permissions * [ ] * Services + Projects + Workshops * Training + Training: On-Site + Training: Scheduled * Expertise + Qt/QML + C++ + 3D / OpenGL * Platforms * Blogs * Videos + KDAB TV * About Us + Working at KDAB