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]Qt not loading an image in a PushButton(Qt 5.0.2 for Windows 64-bit)
Forum Updated to NodeBB v4.3 + New Features

[Solved]Qt not loading an image in a PushButton(Qt 5.0.2 for Windows 64-bit)

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.9k Views 1 Watching
  • 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi all,I am using Qt Creator 2.7.0 Based on Qt 5.0.2 (32 bit) and using the msvc 2012 compiler and I find that the following simplified code fails to load the icon.On my other setup with mingw the image loads without problem.
    @QPushButton * mButton=new QPushButton(this);
    QPixmap mPixmap(":/images/images/addPageResized.png");
    mButton->setIcon(QIcon(mPixmap));@

    Just wondering if this problem is specific to Qt for visual studio 2012 .Any pointers in the right direction would be appreciated.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi, maybe move this topiq to the tools section? Seems to be more a MSVC2012 issue ;-) But your information isn't complete. You say that you downloaded the Qt5.0.2 framework, 32 bits for MSVC2012. That is sort of impossible since that isn't released on the download site. Compiling code with a compiler that wasn't used to compile Qt is highly not recommended! Has to do with namemangling etc. Please first check that the compilers for Qt (downloaded) and your development settings are the same! That might do the trick.
      Code looks fine IYAM
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        [quote author="Jeroentje@home" date="1367566297"]You say that you downloaded the Qt5.0.2 framework, 32 bits for MSVC2012. That is sort of impossible since that isn't released on the download site.[/quote]
        where did he say that??

        [quote author="Jeroentje@home" date="1367566297"]
        Compiling code with a compiler that wasn't used to compile Qt is highly not recommended! [/quote]
        also Qt is available with MSVC2012 (64 bit) ... but the same compiler ...

        @musimbate musimbate
        are you really sure that the image path is correct and you also compiled the qrc into your application and you have compiled the imageformats plugin for PNG in your MSSVC2012 setup?!

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          Thanks all for your answers.
          This is how I got to the setup I have so far.I first had visual studio 2012 installed on my windows7 64 bit system(Which gives me access to the compiler ) and then I downloaded and installed Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB).
          Everything is working I just found that images are not loading as expected.

          I think it has something to do with the image formats plugin.How exactly can I compile those image plugins and where do i get them?
          Thanks for your time.

          Why join the navy if you can be a pirate?-Steve Jobs

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            so you are using a precompiled release package ... it should already contain the imageformat plugins.
            try the following to check if your application can read the image:
            @
            QImageReader imgReader( ":/images/images/addPageResized.png" );
            qDebug() << "can read image?" << imgReader.canRead(); //check if it returns true
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • musimbateM Offline
              musimbateM Offline
              musimbate
              wrote on last edited by
              #6

              I run the imageReader test and it returned false:

              @Starting F:\Qt Projects\build-TestIconPushButton-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\TestIconPushButton...
              can read image? false @

              May be my setup is missing those plugins.Is there an easy way I can install them?From the help menu and going to the about Plugins menu item I cannot find any .png related plugin.

              Thanks.

              Why join the navy if you can be a pirate?-Steve Jobs

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @
                qDebug() << "file exists?" << QFile(":/images/images/addPageResized.png").exists();
                @
                if it returns false:

                clean project

                run qmake

                build project

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • musimbateM Offline
                  musimbateM Offline
                  musimbate
                  wrote on last edited by
                  #8

                  Thanks man!I did exactly as you said and now the images are loading nice and clean!Would you care to briefly explain what was the problem?I am happy it works but it still bugs me not knowing what was wrong.
                  Again thanks a bunch!

                  Why join the navy if you can be a pirate?-Steve Jobs

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    your qrc was not up to date with the binaries....means your image was not coded into your binaries.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • musimbateM Offline
                      musimbateM Offline
                      musimbate
                      wrote on last edited by
                      #10

                      Thanks.Now I consider this thread closed.

                      Why join the navy if you can be a pirate?-Steve Jobs

                      1 Reply Last reply
                      0

                      • Login

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