May 25, 2011

vinb vinb
Lab Rat
205 posts

[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?

10 replies

May 25, 2011

Franzk Franzk
Lab Rat
830 posts

uh. Show some code?

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 25, 2011

vinb vinb
Lab Rat
205 posts

Ok,

In .h:

  1. private:
  2.    QIcon icon; //makes the program crash.
  3.  OR
  4.   QIcon *icon//also crashes.

In a normal function it works like a charme.

May 25, 2011

Franzk Franzk
Lab Rat
830 posts

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

Obviously it isn’t just the fact that you do

  1. 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.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 25, 2011

renato.filho renato.filho
Lab Rat
54 posts

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

May 25, 2011

vinb vinb
Lab Rat
205 posts

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:

  1.     QStandardItem *item = new QStandardItem;
  2.     item->setIcon(QIcon(":/icon/pic5"));

then everything works like a charme.
If i do :
  1.     QStandardItem *item = new QStandardItem;
  2.     QIcon proeficon(":/icon/pic5");
  3.     item->setIcon(proeficon);

everything works like a charme.
If i do:
  1.     QStandardItem *item = new QStandardItem;
  2.     QIcon proeficon;
  3.     proeficon.addFile(":/icon/pic5");
  4.  
  5.     item->setIcon(proeficon);

everything works like a charme.

But if i do:

In header:

  1. QIcon proeficon;

And in the constructor:
  1.     proeficon.addFile(":/icon/pic5");

Then my program crashes.

I hope i did explain it better now?

May 25, 2011

peppe peppe
Ant Farmer
1025 posts

Paste a complete, small, compilable testacase.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

May 25, 2011

vinb vinb
Lab Rat
205 posts

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.

May 25, 2011

vinb vinb
Lab Rat
205 posts

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?

May 25, 2011

Franzk Franzk
Lab Rat
830 posts

Sometimes you just need to rebuild…

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

May 25, 2011

vinb vinb
Lab Rat
205 posts

i thought that i had done that, but clearly not

 
  ‹‹ [Split] setting buttons size      Output of QTestLib unit-tests: "time"-attribute in testcase-element when using -xunitxml ››

You must log in to post a reply. Not a member yet? Register here!