Question

I did everything what I need to do:

  1. added an icon to resource file
  2. initialized resource in main file: Q_INIT_RESOURCE(images);
  3. set icon: ui->action_New->setIcon(QIcon(":/images/about_me.png"));

but still cant see an image when I compile and run my application (I use Kubuntu 12.04 and Qt 4.8.1). Here's a little test project: http://www27.zippyshare.com/v/45362924/file.html. What's wrong and how to fix it?

Was it helpful?

Solution

Pay attention to the alias bit in your .qrc file.

I prefer to set <qresource prefix="/"> to keep it simple.

<RCC>
   <qresource prefix="/">
      <file alias="about me">images/about_me.png</file>
      <file alias="BSD License">otherfiles/LICENSE.txt</file>
      ... 
   </qresource>
</RCC>

This way you don't need to bother remembering the full path to use a resource

ui->action_New->setIcon(QIcon(":/about me"));    
this->setWindowIcon(QIcon(":/about me"));
...

QFile lfile (":/BSD License");
if(lfile.open(QIODevice::ReadOnly){
  ...
}

Note: I'm not suggesting that using spaces in the aliases is a good or bad idea, but it certainly works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top