Results 1 to 9 of 9

Thread: Set QApplication icon without using the rc/qrc file ?

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Set QApplication icon without using the rc/qrc file ?

    Hello,

    I need to set an icon for my application
    But...

    I don't really know how to use the rc file, and I don't want to use it. If I understood weel, it is plateform dependant.

    So there is the qrc file, that seems not to be plateform dependant.
    The matter is that :
    - I don't know how to use it too
    - It seems to load the ressources in memory at the launch of the application. I can't allow that for my application, that need to use as less memory as possible

    Is there another solution ?
    What I would like is to say, for example :
    Qt Code:
    1. QApplication app(argc, argv);
    2. app.setIcon("my_icon.xpm");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Set QApplication icon without using the rc/qrc file ?

    If you set an icon, you have to load it into memory anyway and I'm sure you can spare few hundred bytes for a small png image. But if you don't want it that way, them simply create a QPixmap from file:
    Qt Code:
    1. QApplication app(...);
    2. app.setIcon(QPixmap("my_icon.xpm"));
    To copy to clipboard, switch view to plain text mode 

    just remember that you're using a relative path here.

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Thanks Wysota
    But it says : "QApplication has no member named 'setIcon'


    .
    Last edited by Nyphel; 23rd March 2007 at 08:24.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Quote Originally Posted by Nyphel View Post
    But it says : "QApplication has no member named 'setIcon'
    J-P Nurmi

  5. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set QApplication icon without using the rc/qrc file ?

    So, it isn't possible to set the icon for all environments at the same time ?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Quote Originally Posted by Nyphel View Post
    So, it isn't possible to set the icon for all environments at the same time ?
    You didn't follow and read the links, did you? The icon, which typically displayed in the top-left corner of a window, is set by calling QApplication::setWindowIcon() or QWidget::setWindowIcon():
    • QApplication::setWindowIcon() <== set default window icon for all windows in the application
    • QWidget::setWindowIcon() <== set window icon for a specific window

    This approach is platform independent.

    However, if you want to set an icon for the executable, which is seen in file managers and such, you must use platform dependent solutions. This is all explained in Setting the Application Icon.
    J-P Nurmi

  7. #7
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Thanks jpn.

    What I need is setting the icon for the executable.
    This is the reason why I told about the rc and qrc files

    And yes, I have read the links

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Quote Originally Posted by Nyphel View Post
    What I need is setting the icon for the executable.
    This is the reason why I told about the rc and qrc files
    Ok, in this case there is no other way around than using platform dependent solutions described in.. you already know where. Qt's resource files (.qrc) won't help you with this. You will have to use a Windows resource file (.rc) on Windows and/or other mechanisms appropriate to the platform in question.
    J-P Nurmi

  9. #9
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set QApplication icon without using the rc/qrc file ?

    Thanks jpn .
    I wasn't sure of it, cause Qt is made in order not to be plateform dependant, so I expected there was an other solution .

Similar Threads

  1. QApplication: no such file or directory
    By jochen_r in forum Newbie
    Replies: 13
    Last Post: 15th November 2008, 21:46
  2. QMessageBox Icon Issue and How to add a dir to Qt Resources File
    By vishal.chauhan in forum Qt Programming
    Replies: 19
    Last Post: 25th March 2007, 00:13
  3. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  4. set Icon to .app file
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 21:13
  5. Associating icon with a file type
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2006, 16:57

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.