Results 1 to 4 of 4

Thread: QIcon not shown on Ubuntu, works on Windows

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default QIcon not shown on Ubuntu, works on Windows

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QIcon not shown on Ubuntu, works on Windows

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

  3. #3
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QIcon not shown on Ubuntu, works on Windows

    Well its not that simple. I created a small example but it works on both machines. Here is the example:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. w.show();
    7.  
    8. QToolBar* toolbar = w.addToolBar("Test");
    9. QString icon_path = QApplication::applicationDirPath() + "/xml_icon_16x16.png";
    10. QIcon icon(icon_path);
    11. w.setWindowTitle(icon_path);
    12. QAction* action = new QAction(icon,"Action",0);
    13. toolbar->addAction(action);
    14.  
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: QIcon not shown on Ubuntu, works on Windows

    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

Similar Threads

  1. Does anyone have works with qoauth in windows?
    By MorrisLiang in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2010, 11:02
  2. Replies: 3
    Last Post: 26th August 2010, 12:51
  3. Works well on Windows but fails on Linux
    By utkuaydin in forum Qt Programming
    Replies: 3
    Last Post: 11th January 2010, 14:22
  4. Replies: 8
    Last Post: 8th September 2008, 10:46
  5. Replies: 2
    Last Post: 31st May 2006, 22:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.