My class represents a sequence of items. There can be many instances of such sequences, but they are always displayed in the GUI as a part of a tree structure. The sequence is responsible for filling the tree with its data, and it has its own icon in the tree. Since the icon is the same for all sequences, I made it static:
class Sequence
{
public:
Sequence() { }
/* ... */
protected:
QList<SeqItem *> items_;
static const QIcon treeIcon_;
};
const QIcon Sequence::treeIcon_ = QIcon(":/icons/seq.png");
The problem is that when I run the application, it crashes with:
QPixmap: Must construct QApplication before a QPaintDevice.
Possibly because the static members are created before the main window itself. So my question is: is it possible to have QIcons as static members of my class, and if so, how?
Maybe use static initialization in a function that you call after application initialization.
static QIcon getSeqIcon() {
static QIcon icon = QIcon(":/icons/seq.png");
return icon;
}
Not sure if you also need to destruct it before the application though. If you do, then maybe have a static shared pointer and manually release at application shutdown.
As the error message implies, I think that not. However, you could make the treeIcon_
a static pointer, and have it initialized inside your QApplication
's subclass constructor. Perhaps even better, make it a field inside your QApplication
and use qApp
to access it from inside Sequence
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With