qt imageformats folder

Many qt image related classes allow you to load an image from a file such as:

QIcon ButtonIcon("myprogrammingnotes.com.ico");


QPixmap pixmap("myprogrammingnotes.com.ico");
QIcon ButtonIcon(pixmap);

That is very convenient. But today, I encountered a weird issue: my program can load .bmp files but cannot load .ico files. The .ico file is converted from the .bmp file. Both the .ico file and the .bmp file are displayed without problem in other applications such as MS painter. Why qt cannot display .ico files but can display .bmp files?

It turns out the image format plugin qico.dll is missing. But when I put qico.dll alongside the app directory(the directory of the .exe file of the app), the problem persisted. I put the image format dll in the binary directory of the qt installation directory, the problem still persisted. Putting it in the working directory still cannot solve the problem. In fact, I tried other directories such as C:\build\qtbase\plugins\imageformats, C:\build\qtbase\bin\, C:\build\qtbase\platforms, C:\build-myapp-mingw64-Debug,C:\build-myapp-mingw64-Debug\debug,C:\build-myapp-mingw64-Debug\imageformats\, but none worked.

So, what is the qt imageformats folder? In fact, you can put the qt imageformats-plugin in one of the two folders: C:\build-myapp-mingw64-Debug\debug\imageformats and C:\build\qtbase\platforms\imageformats. When the image format plugins are built, they may be put inĀ  C:\build\qtbase\plugins\imageformats, but to use them, the plugins’dll should be copied to one of the two folders, otherwise, the image file cannot be loaded and displayed. The interesting thing is you do not need a plugin dll to load .bmp file. So next time, if you can not load/display .gif, .icns, .ico, .jpeg, .svg, .tga, .tiff, .wbmp, .webp format of files but can load/display .bmp format of file, you should consider the imageformats folder issue. You should make sure the corresponding dlls exist and they are in proper place. The worst thing is qt won’t complain any error about this problem, even in debug mode. It just ignores the error silently, leaving you lost. Then, you may have to pay them to get support. I bet the directory issue of plugin or imageformats alone may earn them quite a lot of money.

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply