I wish to have a large array of QColors that many classes will share and index from.
In the past, I’ve always had the list like such:
QColor colours[10] = {QColor("cyan"), QColor("magenta"), QColor("red"),
QColor("darkRed"), QColor("darkCyan"), QColor("darkMagenta"),
QColor("green"), QColor("darkGreen"), QColor("yellow"),
QColor("blue")};
However, now I want many more than 10. How can I create a large list of different QColors?
if you want your list to be dynamic, I would use some sort of QVector instead, wrapped in a Color Manager for example :
If your colors have to be unique, consider using a QSet, but you loose the [] operator as QSet are ordered structure, and you will have to implement a find in ColorManager, using QSet::find(). It will also be slower.
If it has to be thread safe, you can eventually protect it with QMutex.
Also, I don’t know why you need this, but you should have a look at :
QColorGroupand / orQPalette