Qt image resource is null
-
There is no Qt png plugin because the support for png is built-in in QtGui so no plugin needed. Therefore it's also not a plugin problem but a problem of your path passed to QFile.
-
@Christian-Ehrlicher Thanks for the response. But the path passed to
QFile
andQImage
orQImageReader
are exactly the same. Even when I use the following approach still cannot get a usableQImage
instance:QFile f(":/resources/images/default-background.png"); f.open(QIODevice::OpenModeFlag::ReadOnly); QByteArray byte_array = f.readAll(); qDebug() <<"Bytes length: " << byte_array.length(); QImage img = QImage::fromData(byte_array); qDebug() << "Is QImage instance null: " << img.isNull();
The output:
Bytes length: 277370 Is QImage instance null: true
So the path is definitely correct.
-
@zhongdongy What if you pass the path to the file into QImage constructor? Get rid of the middle man QByteArray.
-
Here is a sample demonstrating the issue I encountered: GitHub | qt-forum-samples/qimage-not-loading. It's based on the reply I posted above. I'm building this project using MSVC, so the
CMakeLists.txt
file has some extra jobs to copy the debug DLLs. -
Works fine for me after I removed the strange rcc custom command. You enabled CMAKE_AUTORCC so why to you the call rcc by yourself? Remove it and simply add application.qrc to your list of sources as described in the documentation of CMAKE_AUTORCC.
-
@Christian-Ehrlicher The custom command was added because I once suspected the
CMAKE_AUTORCC
was not working correctly. Just now as you suggested, I commented the custom Cmake command, but still no luck.It is very clear now, this command has nothing to do with the
QImage
not loading data but thank you anyway. It somehow just failed on my laptop, I'll try to start a Linux virtual machine and see how.May I know your Qt version? Mine is Qt 6.2.3.
-
My Qt version is 5.15.2 on Linux and 6.2.3 on Win (MinGW)
Bytes length: 277370 qt.gui.icc: fromIccProfile: failed minimal tag size sanity Is QImage instance null: false qt.gui.icc: fromIccProfile: failed minimal tag size sanity Is QImage2 instance null: false
-
@Christian-Ehrlicher Thank you very much. From what we've seen now, the code itself has no issue. I'll try on Linux, or other versions on Windows and see how. I'll update here if I found something.
-
@Christian-Ehrlicher Just now I use a Linux (Ubuntu 21.10) vm to test the same code with GCC, same result as you've posted:
Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. Bytes length: 277370 qt.gui.icc: fromIccProfile: failed minimal tag size sanity Is QImage instance null: false qt.gui.icc: fromIccProfile: failed minimal tag size sanity Is QImage2 instance null: false
And I've already re-installed Windows 11 (code failed) now using Windows 10 host (also failed). This is really frustrating because I'll have to write Qt on a Windows host and compile it inside Linux vm, lol. I cannot use Linux directly because the Intel Iris Xe graphics card shipped with Intel i7-1195G7 has screen tearing issue on almost all Linux distros (Fedora, Arch, Ubuntu, Debian, RH, Deepin...). Spent the whole day yesterday to install and test...
I'll try submit a bug report on bugtracker if none submitted before. Thanks everyone.