Results 1 to 2 of 2

Thread: Runtime error when initializing static const member QPixmap

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Runtime error when initializing static const member QPixmap

    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

  2. #2
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Runtime error when initializing static const member QPixmap

    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.

Similar Threads

  1. Replies: 22
    Last Post: 8th October 2008, 13:54
  2. const member and const method
    By mickey in forum General Programming
    Replies: 8
    Last Post: 9th April 2008, 09:44
  3. Replies: 3
    Last Post: 19th February 2008, 13:10
  4. QHash static member error
    By ramazangirgin in forum Qt Programming
    Replies: 7
    Last Post: 5th February 2008, 11:26
  5. const member definitions in a class ....
    By TheKedge in forum General Programming
    Replies: 5
    Last Post: 15th February 2006, 13:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.