Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QSystemTrayIcon icon from resource file isn't showing

[SOLVED] QSystemTrayIcon icon from resource file isn't showing

Scheduled Pinned Locked Moved General and Desktop
iconqsystemtrayiconresource
26 Posts 4 Posters 15.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartinH
    wrote on 1 Jul 2015, 13:00 last edited by
    #9

    Huum if you're using QtCreator, open the file tree, open the tree of your resource file then do a right click on your image file. Click on copy full path (or something like that) then paste the path in your code :)

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nitzan
      wrote on 1 Jul 2015, 13:03 last edited by
      #10

      I tried that yesterday but it did not help, and looked weird as this is what I get:

      ://images/appicon.png
      

      which has two slashes while I usually see only one used.

      in any case, I tried it now again and to no avail, I get the same result.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MartinH
        wrote on 1 Jul 2015, 13:04 last edited by
        #11

        No, theorically qt creator propose to you a second option wich start with

        qrc:/

        You've it or not ?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nitzan
          wrote on 1 Jul 2015, 13:11 last edited by
          #12

          Nope.

          All I have when I right click on the image in the resource editor is "Copy Resource Path to Clipboard" and the result is what I posted.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MartinH
            wrote on 1 Jul 2015, 13:50 last edited by
            #13

            No, not in the resource editor, in the file tree on the left !

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nitzan
              wrote on 1 Jul 2015, 13:55 last edited by
              #14

              Oh. sorry about that.

              I tried that now as well, and the same thing happens (or doesn't happen).

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ambershark
                wrote on 2 Jul 2015, 00:46 last edited by
                #15

                It tries to scale images, but it you were using a really crazy size it may exhibit behavior like that. What happens if you do this:

                QLabel *label = new QLabel();
                label->setPixmap(QPixmap(":/images/appicon.png");
                label->show();
                

                If it shows there then you may have an issue with it being converted to a QIcon in which case I would check your sizing of the image. I.e. try to get it no more than like 32x32 for that area since it is going to scale down to 16x16 more than likely.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nitzan
                  wrote on 2 Jul 2015, 10:02 last edited by
                  #16

                  Well, doing that was a bit over my Qt skills (controlling qml from c++), but I tried using a different image.
                  I created a 16x16 one color png, added that to the resource file and tried using that, but once again to no avail.
                  So it's probably not the image I was trying to use, but a problem with the resources or how I try to fetch them.

                  Any ideas?
                  Thanks.

                  A 1 Reply Last reply 2 Jul 2015, 23:40
                  0
                  • N nitzan
                    2 Jul 2015, 10:02

                    Well, doing that was a bit over my Qt skills (controlling qml from c++), but I tried using a different image.
                    I created a 16x16 one color png, added that to the resource file and tried using that, but once again to no avail.
                    So it's probably not the image I was trying to use, but a problem with the resources or how I try to fetch them.

                    Any ideas?
                    Thanks.

                    A Offline
                    A Offline
                    ambershark
                    wrote on 2 Jul 2015, 23:40 last edited by
                    #17

                    @nitzan I just noticed in your resource file you don't have a prefix. Maybe try the following qrc file:

                    <!DOCTYPE RCC>
                    <RCC version="1.0">
                        <qresource prefix="/">
                            <file>images/appicon.png</file>
                        </qresource>
                    </RCC>
                    

                    Notice that prefix="/" on <qresource>.

                    I also removed the alias so there isn't any issue there. Then in your load code do:

                    trayIcon->setIcon(QIcon(":/images/appicon.png"));
                    

                    I think that might work. If not let me know any I'll write up a quick example that does work and send you the code and you can compare it to yours and figure out what is missing. :)

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nitzan
                      wrote on 5 Jul 2015, 11:16 last edited by
                      #18

                      I added the prefix and it had no effect.
                      Here's my current code.

                      Resource file:

                      <!DOCTYPE RCC>
                      <RCC version="1.0">
                          <qresource prefix="/">
                              <file>images/appicon.png</file>
                              <file>images/simpleIcon.png</file>
                          </qresource>
                      </RCC>
                      

                      cpp file:

                      QAction* quitAction = new QAction(QIcon(":/images/appicon.png"), QObject::tr("&Quit"), &app);
                      app.connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
                      
                      QMenu* trayIconMenu = new QMenu();
                      trayIconMenu->addAction(quitAction);
                      
                      QSystemTrayIcon* trayIcon = new QSystemTrayIcon();
                      trayIcon->setContextMenu(trayIconMenu);
                      trayIcon->setIcon(QIcon("qrc:/images/simpleIcon.png"));
                      trayIcon->show();
                      

                      The appicon is the original icon, with an image which is 83x83, and the simpleIcon is just a 16x16 solid color image.
                      Both aren't showing.
                      Thanks.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        ambershark
                        wrote on 7 Jul 2015, 07:10 last edited by
                        #19

                        @nitzan Sorry, got a ton going on at work right now. I will be able to mess around with your code a bit tomorrow probably and I'll let you know what I find out.

                        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          nitzan
                          wrote on 7 Jul 2015, 10:29 last edited by
                          #20

                          Something weird happened.
                          I haven't changed anything but now I do see an icon in the QAction, but not in the tray, even if I use the same exact object, like so:

                          QIcon icon(":/images/appicon.png");
                          QAction* quitAction = new QAction(&icon, QObject::tr("&Quit"), &app);
                          ...
                          QSystemTrayIcon* trayIcon = new QSystemTrayIcon();
                          trayIcon->setIcon(&icon);
                          ...
                          

                          No idea what causes the icon to show up all of the sudden in the QAction, but fine, whatever..
                          The question is why will the icon show up there but not in the tray?

                          Thanks.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            ambershark
                            wrote on 7 Jul 2015, 21:07 last edited by
                            #21

                            That sounds like a build issue. Try making sure your build environment is totally clean and rebuild. Check out a fresh copy from source control even. Or at a bare minimum make distclean then make.

                            See if that resolves your icon issues.

                            I'll still play with your code in a bit, just haven't had time yet.

                            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                            1 Reply Last reply
                            0
                            • N Offline
                              N Offline
                              nitzan
                              wrote on 7 Jul 2015, 22:44 last edited by
                              #22

                              You're right, it's a build issue.

                              Rebuilding it produced many errors it did not complain about before, meaning that all of the last time I clicked the run button did not really compile my changed code and I kept checking the same thing.

                              Now it's stuck on

                              qtmaind.lib(qtmain_win.obj):-1: error: LNK2019: unresolved external symbol _main referenced in function _WinMain@16
                              

                              No matter what I do, I tried running qmake, cleaning all and rebuilding all but nothing seems to make it want to recompile my changed code.
                              There's nothing to check out, it's a completely new project with the minimum of code I posted.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                ambershark
                                wrote on 8 Jul 2015, 00:06 last edited by ambershark 7 Aug 2015, 00:06
                                #23

                                Ok then this is probably not an icon issue with systray. In fact one of the suggestions above probably fixed it but we never knew because of the build issues.

                                So moving on to the build issues:

                                1. Can you show me your *.pro file?
                                2. What OS are you using?
                                3. What IDE are you using since you said "clicked run" before I'm assuming you aren't using the command line. :)
                                4. What compiler are you using?

                                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                1 Reply Last reply
                                0
                                • N Offline
                                  N Offline
                                  nitzan
                                  wrote on 8 Jul 2015, 08:35 last edited by
                                  #24

                                  Yes, you are correct again.
                                  I created a new project and copied just the icon related code and the icon does appear now in the tray.

                                  As for the build issue:
                                  I'm developing on windows 8.1, using the Qt Creator (as I can't seem to find an addin to visual studio 2013 (I found this: http://download.qt.io/official_releases/vsaddin/qt-vs-addin-1.2.4-opensource.exe.mirrorlist but it won't run on my machine).
                                  But it uses the VS2013 compiler.

                                  Here's my .pro file:

                                  TEMPLATE = app
                                  
                                  QT += qml quick widgets
                                  
                                  HEADERS += source/*.h
                                  SOURCES += source/*.cpp
                                  
                                  RESOURCES += qml.qrc \
                                  	images.qrc
                                  
                                  # Additional import path used to resolve QML modules in Qt Creator's code model
                                  QML_IMPORT_PATH =
                                  
                                  # Default rules for deployment.
                                  include(deployment.pri)
                                  
                                  DISTFILES += \
                                  	images/appicon.png
                                  
                                  #win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/release/ -llibcef
                                  #else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/debug/ -llibcef
                                  
                                  #INCLUDEPATH += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32
                                  #DEPENDPATH += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32
                                  
                                  #win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/release/liblibcef.a
                                  #else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/debug/liblibcef.a
                                  #else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/release/libcef.lib
                                  #else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../CEF/cef_binary_3.2357.1280.geba024d_windows32/debug/libcef.lib
                                  

                                  As can be seen, I added a library (chromium embedded framework) but after reading about how that error is caused when adding additional libs I commented it out, but still that error would not go away.
                                  It's probably something to do with the Qt Creator which caches things?

                                  1 Reply Last reply
                                  0
                                  • N Offline
                                    N Offline
                                    nitzan
                                    wrote on 8 Jul 2015, 09:22 last edited by
                                    #25

                                    Ok, I finally managed to get everything working!

                                    What I did was to set the Default build directory to . instead of what it has there, and I unchecked the Use jom instead of nmake box.
                                    Now it seems to actually rebuilding the up to date code.

                                    Thanks for all the help!

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      ambershark
                                      wrote on 13 Jul 2015, 22:24 last edited by
                                      #26

                                      Good, glad ya got it sorted out. Sorry I've been super busy lately and haven't lurked the forums here. :)

                                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                      1 Reply Last reply
                                      0

                                      18/26

                                      5 Jul 2015, 11:16

                                      • Login

                                      • Login or register to search.
                                      18 out of 26
                                      • First post
                                        18/26
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved