[Qt-interest] Playing files from resource files

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Tue Dec 16 19:24:52 CET 2008


[Accidentally sent to me in private]

Tiago Correia wrote on Tuesday, December 16, 2008 7:07 PM:

> Hi,
>
>
>
>       Try opening the generated qtc_[YourResourceFile].cpp and look for
>        static const unsigned char qt_resource_struct[] = {
>           ...
>        }
>
>       Inside this struct there should be (generated) comments with the
> resource paths you'd have to use within your code, e.g.
>
>        // :/Project/img/ApplicationIcon32x32.png
>
> Since I'm using windows, here I get the full path for my system. Not
> the path to use inside the code.

Well, Windows, Linux, Mac... doesn't matter: the Qt resource compiler should always generate identical code (apart from the *original* file paths being used, off course, the one you just mentioned). ;)

As a matter of fact I am currently also developing on Windows, using VS 2005 Express.

But I assume what you are looking at - the "full path" - is the comment just above

  static const unsigned char qt_resource_data[] = {
     // D:/home/tknoll/work/[...]/Project/Resources/img/ApplicationIcon32x32.png

That's xxx_DATA, on the very top of the generated file - but I was talking about xxx_STRUCT ;) So scroll down a bit and you'll find

  static const unsigned char qt_resource_struct[] = {

And there you go, you'll find the "resource paths" :)

> ...
> It must be and QIODevice, and QBuffer is an QIODevice and QByteArray
> not.

That's what I thought. So the problem could really be that "buffering Qt resources" does not go well with Phonon... (a bug in Qt?)

> I managed to solve the problem of using the resource file, or at
> least to load it.
>
> My problem was that I was using a library to handle all the playing
> movie part, and when I added my lirbary to other project I was not
> able to access the resource files that this library added (this is
> another problem, quite strange).

Was that a static library? If yes, the following might apply to your situation:

http://doc.trolltech.com/4.4/resources.html:
"If you have resources in a static library, you might need to force initialization of your resources by calling Q_INIT_RESOURCE() with the base name of the .qrc file. For example: [...]"

I can confirm though that using resources from another DLL works (in fact I once had a project which contained a Resource.dll which basically just had the icon images embedded).

> To solve I just added the resource
> file directly on the main project, and the file already open without
> problems.
>
> Now the problem is when I try to change the centralWidget for the
> VideoWidget, the application crashed on this line of code
>
> setCentralWidget( myWidget );
>
> Now this bug only happens when using the QBuffer. If I now use the
> filename for the MediaSource, it works, but only for the local file.
>
> So to better understand:
> QBuffer with :/video.mpg -> not working
> QBuffer with video.mpg -> not working
> String with :/video.mpg -> not working
> String with video.mpg -> working
>
> So, does anyone, add a similar experience?

Hmmm, where exactly does it crash? Can you show us a stack trace, for example?

Cheers, Oliver

p.s. Don't forget to change the To: address to qt-interest at trolltech.com next time before sending ;)
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22




More information about the Qt-interest-old mailing list