-
Notifications
You must be signed in to change notification settings - Fork 50
Developer Notes for Qt Code
The source code must be compatible with the minimum required Qt version which is set in configure.ac
:
BITCOIN_QT_CONFIGURE([5.5.1])
If an optional feature requires a higher version of Qt, or if a feature was replaced by another one, use the QT_VERSION
and QT_VERSION_CHECK
macros:
#include <QDate>
#include <QDateTime>
#include <QtGlobal> // For QT_VERSION and QT_VERSION_CHECK macros.
QDateTime StartOfDay(const QDate& date)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return date.startOfDay(); // QDate::startOfDay was introduced in Qt 5.14.0.
#else
return {date};
#endif
}
Do not compare versions of QT_VERSION
directly using 0xMMNNPP
(MM = major, NN = minor, PP = patch), as this approach is less readable and more error-prone.
Every time the minimum required Qt version is bumped, grep
or git grep
for all of the QT_VERSION
instances and adjust/remove them accordingly.
When sublassing the QObject
class follow the pattern below:
#include <QObject>
class MyWidget : public QObject
{
Q_OBJECT
public:
// Public members.
public Q_SLOTS:
// Public slots.
Q_SIGNALS:
// Signals (inherently public).
private:
// Private members.
private Q_SLOTS:
// Private slots.
};
Use the Q_SIGNALS
and Q_SLOTS
macros instead of the signals
and slots
keywords of the Qt moc
(Meta-Object Compiler). This prevents potential conflicts with 3rd party signal/slot mechanisms.
For debugging, including signal-to-slot connection issues, you can use the QT_FATAL_WARNINGS
environment variable:
$ QT_FATAL_WARNINGS=1 src/qt/bitcoin-qt -printtoconsole -debug=qt
This tip can be combined with a debugger.
More notes come soon...