[SOLVED]can not declare QIcon in class?

  • Hi all,

    I have a "strange" problem.
    I want to declare a QIcon in my header file(class) and set its filename in the constructor.
    But when i add "QIcon icon;" in my class, the program crashes when started.
    When i add "QIcon icon" in a constructor/function it works as it should be.

    Can someone please explain if im doing something wrong here?

  • uh. Show some code?

  • Ok,

    In .h:
    QIcon icon; //makes the program crash.
    QIcon *icon//also crashes.

    In a normal function it works like a charme.

  • Just for kicks, change the name to m_icon and see what happens.

    Obviously it isn't just the fact that you do @QIcon *icon@ in some header. There is more to this. The code snippet you showed is just as good as the description you gave. If the above doesn't work, we will need a lot more context to the problem.

  • can you produce a small example with this problem? (only a small class with QIcon)

  • Hi Franzk,

    I'm sorry if i'm not clear here, so i try to explain myself a little better now.

    I'm writing a little test program where i want to have a icon shown in a listview.

    if i use a function call like:
    @ QStandardItem *item = new QStandardItem;
    then everything works like a charme.
    If i do :
    @ QStandardItem *item = new QStandardItem;
    QIcon proeficon(":/icon/pic5");
    everything works like a charme.
    If i do:
    @ QStandardItem *item = new QStandardItem;
    QIcon proeficon;


    everything works like a charme.

    But if i do:

    In header:
    QIcon proeficon;
    And in the constructor:
    Then my program crashes.

    I hope i did explain it better now?

  • Paste a complete, small, compilable testacase.

  • Recall:
    i just made a small example with only a qicon in the class, but the problem didnt accure.
    So i have to puzzle a little bit more, to narrow the problem down.

  • Solved:
    Very strange,
    I just copied the whole class to another one and it worked like expected. So there was nothing wrong with the code.
    So i deleted the whole build folder to force creator to build again and everything worked perfectly after that.
    Does somebody know what was going on here?

  • Sometimes you just need to rebuild...

  • i thought that i had done that, but clearly not

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.