Qt: custom-class and specialities for QVariant and QSettings

Written by  on December 11, 2019 

While implementing some custom-class (C++17; Qt5.12) some specialities became (painfully) noticeable.
The guide at the Qt-source is quite well written.

  • ctor, copy-ctor and dtor are all required and have to be public
  • add Q_DECLARE_METATYPE(CustomClass)
  • QDebug-stream-operator in case of simple debugging-messages
  • if the QVariant-version of the CustomClass shall be written to QSettings, then implement also the two streaming operators: << and >> (else crash with Assert “unable to save type”): howto

Category : C++Qt