PDA

View Full Version : Runtime error when initializing static const member QPixmap



shiona
23rd September 2010, 15:56
Using QT 4.7.0 (creator 2.0.0)
A simple static const member initilization seems to cause MSVC runtime error, so QT Creator IDE won't even start the debugger.
The program ends with error code 3 and prints "Invalid parameter passed to C runtime function."

My code as follows, including tests to narrow the possible errors:

class.h

Class {
--
private:

static const QPixmap defaultIcon;
static const QPixmap* defIcon;

static const char test;
static const QChar test2;
static const char test3[4];
static const QChar test4[4];
static const QChar* test5[4];
};

end of class.h

class.cpp

// These two will both compile, but either will result in runtime error
const QPixmap Node::defaultIcon = QPixmap();
const QPixmap* Node::defIcon = new QPixmap();

// All these compile and work well
const QPixmap* Node::defIcon = 0;
const char Node::test = 'a';
const QChar Node::test2 = 'b';
const char Node::test3[4] = {'c', 'd', 'e', 'f'};
const QChar Node::test4[4] = {QChar('g'), QChar('h'), QChar('i'), QChar('j')};
const QChar* Node::test5[4] = { new QChar('k'), 0, 0, 0 };

end of class.cpp

shiona
23rd September 2010, 18:12
Ok, found out after some more googling.

In case someone else hits this problem:
It seems the constructor of QApplication makes some initializations of Qt itself, before which no "complex" Qt object can be created (It seems QPixmap is complex, QChar is not). The solution I ended up using was to make static pointer and initilizing it in a static method, which is called in the first lines after UI setup.