Using Qt Resources / Files with Irrlicht (IrrlichtQtFile)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
marsupial
Competition winner
Posts: 6
Joined: Mon Feb 26, 2007 4:07 pm
Location: Münster, Germany

Using Qt Resources / Files with Irrlicht (IrrlichtQtFile)

Post by marsupial »

Hey,

Qt brings a very nice resource system that allows you to easily embed files to your executable (http://qt-project.org/doc/qt-4.8/resources.html).
Normally, you just pass ":/your/file/within/the/resources.png" as parameter to open a file from the resources. But that, of course, only works for the Qt file classes, not for the Irrlicht ones.

To be able to e.g. load mesh files, textures etc. from the resources, I wrote a small wrapper class that wraps the functionality of QIODevice (and thus also QFile) to the irr::io::IReadFile and irr::io::IWriteFile interfaces.

Code:
The code is available here:
https://bitbucket.org/hedgeware/irrlichtqtfile/src

Licence:
I don't know if it is neccessary, but just to be clear and assure best licence compatibility with Irrlicht: The above code is licenced under the Irrlicht licence, so you are free to use it in almost every way imaginable.

Example:

Code: Select all

#include "CQtReadFile.h"
// ...
CQtReadFile* myfile = new CQtReadFile(":/my_resources/skybox_texture.png");
ITexture* my_texture = video_driver->getTexture(myfile);
myfile->drop();
Other features:
I have not yet tried, but since you can pass any QIODevice to the constructor of CQtReadFile, it should be possible to use QBuffer and even use network sockets (which in Qt also derive from QIODevice) to read meshes, although the whole data probably needs to be available (and thus already sent). I may look into that later on (or maybe someone else? :))

Thanks,
marsupial
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Re: Using Qt Resources / Files with Irrlicht (IrrlichtQtFile

Post by Dareltibus »

Nice, strange no one still answered :). some times ago I rember there was TONS of people asking for such embedding.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Using Qt Resources / Files with Irrlicht (IrrlichtQtFile

Post by hendu »

You don't need a Qt-specific way to embed, it's just nice to use if you already use Qt.

If you take a look at some of the demos I've posted (vertex texture comes to mind), they have embedded files in the executable using just irr.
marsupial
Competition winner
Posts: 6
Joined: Mon Feb 26, 2007 4:07 pm
Location: Münster, Germany

Re: Using Qt Resources / Files with Irrlicht (IrrlichtQtFile

Post by marsupial »

hendu wrote:You don't need a Qt-specific way to embed, it's just nice to use if you already use Qt.
If you take a look at some of the demos I've posted (vertex texture comes to mind), they have embedded files in the executable using just irr.
I agree, there indeed are different ways of embedding files into the executable and of course you don't need Qt to do that.
Personally I like to utilize Qt's resource system because it fits in very well with Qt applications, is highly portable and easy to set up.

But you are right that those classes probably only make sense, if you use Qt anyway - although the many subclasses of QIODevice povide many ways of handling data in your application (Network, Local files, resources, QBuffer) ;)

Thanks for your replies!
marsupial
Post Reply