0

I have two objects QColor, QFont and there's a possibility of adding more.
I want to store that objects in a container for instance QList but this container needs one type of data.

QFont font = QFontDialog::getFont(&fontDlgRet, initFont, parent);
QColor color = QColorDialog::getColor(initColor, parent);

Is there a container accepts adding different types of objects?

Lion King
  • 32,851
  • 25
  • 81
  • 143

1 Answers1

1

Is there a container accepts adding different types of objects?

Yes: QVariantList, QVariantMap, QVariantHash.

You can also roll your own manually, like std::vector<QVariant> for instance.

See http://doc.qt.io/qt-5/qvariant.html

Also, note that loosing type information like this is frowned upon and bad practice. If you have a finite set of types you can use std::variant instead.

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75