PDA

View Full Version : QIcon not shown on Ubuntu, works on Windows



JPNaude
10th November 2010, 13:02
Hi

I have a problem in multiple applications which were all developed on a Windows machine. When I build the same apps on Ubuntu and run them, no icons are shown (not in the toolbar, list widget etc.).

Here is a few things that I've figured out while trying to fix it:
1) One of the things I tested with is a dynamic library which provides a widget with icons in a toolbar. When create two different apps and show the widget from the library in them, it works in one and does not work in the other.
2) All icons are .png files.
3) It happens both for icons in resource files as well as icons for which I specify the icon's path on the hard drive.

Any ideas why this might happen will be appreciated?

Ubuntu distribution & Compiler: gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)

Thanks,
Jaco

tbscope
10th November 2010, 13:25
A working, compilable and minimal example demonstrating the problem is also appreciated.
It's very difficult to answer what could be wrong (well, at least for me).

JPNaude
10th November 2010, 14:45
Well its not that simple. I created a small example but it works on both machines. Here is the example:



#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.show();

QToolBar* toolbar = w.addToolBar("Test");
QString icon_path = QApplication::applicationDirPath() + "/xml_icon_16x16.png";
QIcon icon(icon_path);
w.setWindowTitle(icon_path);
QAction* action = new QAction(icon,"Action",0);
toolbar->addAction(action);

return a.exec();
}


After playing around with it more, I realized that it looks like a resource system issue. I found that if I have an application like the one above, the shows the icon in Windows & Ubuntu. However if I link this application to a library which also has a resource file with icons embedded in the library, only icons from one of the two resources will show in Ubuntu but it works in Windows.

I tested this by running an app as shown above then it works. Then I link it against a library with an icon in a resource file and show this icon as well, then it does not work. Then I remove the resource file from the main application and then the icons from the library works.

I am probably missing something in regard with the Qt Resource System but I can't figure out what since it always worked on Windows. I've seen the Q_INIT_RESOURCE() macro but it says that it is only related to static libraries, not dynamic libraries which is used in my case.

Thanks for your time,
Jaco

JPNaude
11th November 2010, 05:28
Ok, solved it!

The problem was not related to QIcon in the end but to the resource system. I had multiple libraries with resource files, all named "resources.qrc". Looks like the name must be unique since giving them all unique names solves the issue.

Thanks,
Jaco