1

I have develop a file browser in Qt/C++. I'm displaying the files and folders but I want to add an icons if it's a files or a folders.

I have used :

item->setIcon(0,*(new QIcon(":images/file.jpg")));

But nothing is displayed. I have add the file into the project, it appears in the "Other Files"/"images" folder of the project.

Do I need to declare the file in other location and how ?

Thanks

Seb
  • 2,929
  • 4
  • 30
  • 73
  • 1
    If you are using the [resource system](http://qt-project.org/doc/qt-5/resources.html) like it seems, then your path should be something like `":/images/file.jpg"`. – thuga Nov 19 '14 at 07:36
  • 1
    Replace `file.jpg` with another .png image file. If that works, you have to think about missing jpg image plugin in your application. – vahancho Nov 19 '14 at 07:42
  • 4
    `*(new QIcon(":images/file.jpg"))` is an instant memory leak, by the way. Just `QIcon(":images/file.jpg")` would be correct. – seldon Nov 19 '14 at 07:56

1 Answers1

0

Are you developing with Qt Creator?

I think there are 2 approachs to solve this problem:

1) Try to load the file as new QIcon("qrc:/images/file.jpg"); Maybe there is a problem loading from the resources.

2) Try to change the jpg to a png file as vahancho said (jpeg library must be attached to the project to support jpeg in qt) - Jpeg qt plugin

Regards.

Community
  • 1
  • 1
mpcarlos87
  • 132
  • 10