Hi... I am trying to load a texture from a .qrc file which contains my texture file. I tried to google for it but I got no relevant search result so I'm posting it here. Here's what I did.
QResource Image(":/test.bmp");
sf::Texture Tex;
Tex.loadFromMemory(Image.data(), Image.size(), sf::IntRect());
The texture is not being loaded and fails to show. I checked and found that
loadFromMemory() takes
const void* for data, and
std::size_t for size and the QResource's
data() returns a
const unsigned char* as return value and
size() returns
long long int as return value. So I tried the following two methods.
Tex.loadFromMemory((const void*)Image.data(), (std::size_t)Image.size(), sf::IntRect());
Tex.loadFromMemory(static_cast<const void*>(Image.data()), static_cast<std::size_t>(Image.size()), sf::IntRect());
Still the same result. The image does not load. Here's the application output.
Starting C:\Users\WDR\Documents\Qt\test\debug\test.exe...
Failed to load image from memory, no data provided
C:\Users\WDR\Documents\Qt\test\debug\test.exe exited with code 0
Please tell me the right way to do this. Thank you.