-
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 the configure.ac
:
BITCOIN_QT_CONFIGURE([5.5.1])
If an optional feature requires Qt higher version, or a feature was replaced by another one, use 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 QT_VERSION
directly to Qt version of the form 0xMMNNPP
(MM = major, NN = minor, PP = patch) as such an approach is less readable and more error prone.
Every time the minimum required Qt version is bumped, grep
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.
};
Note that Q_SIGNALS
and Q_SLOTS
macros are used instead of the signals
and slots
keywords of the Qt moc
(Meta-Object Compiler). It prevents potential conflicts with a 3rd party signal/slot mechanism.
More notes come soon...