[Solved]Qt not loading an image in a PushButton(Qt 5.0.2 for Windows 64-bit)
-
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.
-
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 -
[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?! -
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. -
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
@ -
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.
-
@
qDebug() << "file exists?" << QFile(":/images/images/addPageResized.png").exists();
@
if it returns false:clean project
run qmake
build project
-
your qrc was not up to date with the binaries....means your image was not coded into your binaries.