Disconnecting lambda functions in Qt5

If you capture conn directly, you’re capturing an uninitialised object by copy, which results in undefined behaviour. You need to capture a smart pointer: std::unique_ptr<QMetaObject::Connection> pconn{new QMetaObject::Connection}; QMetaObject::Connection &conn = *pconn; conn = QObject::connect(m_sock, &QLocalSocket::readyRead, [this, pconn, &conn](){ QObject::disconnect(conn); // … } Or using a shared pointer, with slightly greater overhead: auto conn = std::make_shared<QMetaObject::Connection>(); … Read more

Image rounded corners in QML

A built-in official solution exists as of Qt 5 thanks to the QtGraphicalEffects module and I’m quite surprised to find out that no one provided such a simple solution. If you are targeting Qt 6.x QtGraphicalEffects is unfortunately deprecated so jump to the second part of the answer which proposes a solution independent of QtGraphicalEffects. … Read more

Dark theme for Qt widgets?

No, but you may use my fairly comprehensive stylesheets that should look excellent on most platforms (it’s inspired by KDE’s Breeze Theme, which is a dark theme that is quite elegant). This was (hard) forked from the excellent QDarkStylesheet, which I felt had theme issues in numerous areas, so I modified it extensively for my … Read more

Building Qt5 with Visual Studio 2012 / Visual Studio 2013, and integrating with the IDE

This method is tested to work on Visual Studio 2013. Pre-built binaries using Visual Studio 2012 and 2013 are available here, including OpenGL versions. Step 1: The Setup Download and install RapidEE here. RapidEE is a windows environment variables editor. It is extremely useful for the rest of this process (and just in general). Install … Read more

QTextEdit vs QPlainTextEdit

From Qt’s documentation: QPlainTextEdit is an advanced viewer/editor supporting plain text. It is optimized to handle large documents and to respond quickly to user input. QPlainText uses very much the same technology and concepts as QTextEdit, but is optimized for plain text handling. QPlainTextEdit works on paragraphs and characters. A paragraph is a formatted string … Read more

Qt Creator, ptrace: Operation not permitted. What is the permanent solution?

If running Ubuntu, The recommended way to enable the needed ptrace kernel setting (hinted by qtcreator) is to edit /etc/sysctl.d/10-ptrace.conf sudo vim /etc/sysctl.d/10-ptrace.conf Then change kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0 Save, then apply: $ sudo sysctl –system -a -p|grep yama kernel.yama.ptrace_scope = 0 run man sysctl for more info.

Building Qt 5 on Linux, for Windows

Here are the full instructions: Get it: git clone https://github.com/mxe/mxe.git Install build dependencies Build Qt 5 for Windows: cd mxe && make qtbase This will first build its dependencies and the cross-build tools; It should take less than an hour on a fast machine with decent internet access. Due to the new modular nature of … Read more