QSound and embedded resources
I was trying to load a wavefile for QSound from a qrc but of no luck. I tried loading the file from my drive then QSound made its sound. I am suspecting my QSound did not find the file in qrc. Is there any trick? I did all these in the snippet below
Code:
int main (int argc,char *argv[])
{
QPixmap pixmap
(":/Menu/tool.gif");
//QPixmap foound this file in my qrc splash.show();
app.processEvents();
QSound::play(":/Sounds/voices/welcome.wav");
//I did not hear any on this one
MyWindow*mainWin = new MyWindow;
mainWin->setMinimumSize(1024,740);
mainWin->show();
splash.finish(mainWin);
return app.exec();
}
my qrc look like this
Code:
<qresource prefix="/Menu" >
<file>tool.gif</file>
</qresource>
<qresource prefix="/Sounds">
<file>voices/welcome.wav</file>
</qresource>
anything i missed?
baray98
Re: QSound and embedded resources
Quote:
Originally Posted by
baray98
anything i missed?
You missed the docs:
Quote:
Note that QSound does not support resources. This might be fixed in a future Qt version.
Re: QSound and embedded resources
Is there already a Qt version where QSound supports resources?
Re: QSound and embedded resources
Nope.
However, you could use this trick:
1) define a class (ResourceFile) that will copy a resource to disk (in the hard-coded "resources" directory at executable file level in this example)
Code:
#ifndef RESOURCEFILE_H
#define RESOURCEFILE_H
#include <QFile>
#include <QString>
class ResourceFile
: public QFile{
public:
};
#endif // RESOURCEFILE_H
Code:
#include "resourcefile.h"
#include <QFileInfo>
#include <QDir>
#define FILES_DIR "resources"
{
if (!files.cd(FILES_DIR))
{
files.mkdir(FILES_DIR);
files.cd (FILES_DIR);
}
setFileName (files.filePath(resource.fileName()));
if (!exists())
{
{
{
write(resfile.readAll());
close();
}
resfile.close();
}
}
}
2) define a class (ResourceSound) that will plug QSound to the disk copy
Code:
#ifndef RESOURCESOUND_H
#define RESOURCESOUND_H
#include <QSound>
#include "resourcefile.h"
class ResourceSound
: private ResourceFile,
public QSound{
public:
: ResourceFile (respath, parent)
,
QSound (fileName
(), parent
) {}};
#endif // RESOURCESOUND_H
You can then use ResourceSound instead of QSound and get the same result (or lack of, considering the shortcomings of QSound :)).
Re: QSound and embedded resources
is that official, is QSound QSoundEffect not able to work with embedded resources?