1

I use the qt resource system with png files. I create .a qrc file where I specify all the pictures I need and add it to my CMakeLists. The following code works great:

QPixmap pix(":/resources/image.png");

But can I somehow use compiled resources with other libraries, for example SFML? The following code won't work, are there any alternative ways?

sf::Texture txt;
sf::Sprite spr;
txt.loadFromFile(":resources/player.png");
spr.setTexture(txt);
vltimvtxx
  • 27
  • 2
  • 1
    https://forum.qt.io/topic/13131/how-to-extract-a-resource-from-qrc-solved – RoQuOTriX Aug 31 '22 at 11:50
  • 1
    Why would you expect SFML (or some other libraries) to understand Qt's resources? – Jesper Juhl Aug 31 '22 at 12:43
  • Thanks for the answers! The solution to the problem turned out to be simpler than it seemed. I just used text.loadFromMemory(), in which parameters I passed the beginning and the size of the file. Anyway, I decided to give up using Qt and replaced it with a script from github https://github.com/vector-of-bool/cmrc . It seemed simpler and more attractive to me. – vltimvtxx Aug 31 '22 at 13:33
  • :) I just found this: [https://caiorss.github.io/C-Cpp-Notes/resources-executable.html](https://caiorss.github.io/C-Cpp-Notes/resources-executable.html) which seems to be related to the above link.. – drescherjm Aug 31 '22 at 13:35

1 Answers1

0

Closed. I just used text.loadFromMemory(), in which parameters I passed the beginning and the size of the file.

vltimvtxx
  • 27
  • 2
  • Can you explain better your solution as with an explanation it could help other users. Did you use this: [https://doc.qt.io/qt-5/qresource.html](https://doc.qt.io/qt-5/qresource.html) – drescherjm Aug 31 '22 at 13:43
  • I completely replaced qt with a script from github for cmake, it seemed more convenient to me. I'm sorry if this solution is not suitable for you. https://github.com/vector-of-bool/cmrc – vltimvtxx Sep 03 '22 at 01:08