Qt-interest Archive, May 2007
weird QSound subclassing issue
Message 1 in thread
Hello,
This may not be a Qt issue, but rather C++. However, since it involves
QSound, I thought I'd post here.
<rant mode>
btw, why on earth did TT *not* build QSound over Alsa ??????????????????????
they do a pretty good job overall , but this is beyond my understanding.
</rant mode>
Ok, I have this is my code :
clickSound = SoundFactory::newSound( "/usr/share/myApp/sounds/click.wav" );
clickSound->play();
What it should do is create a QSound on any non linux platform, and a
QAlsaSound [rant, rant, rant] which subclasses QSound, on Linux
When the QAlsaSound gets constructed, the code within gets actually
executed.
But when the play() function is called from outside (clickSound->play()),
the code of the subclass is not executed.
(when play is called from within QAlsaSound code, it works, though)
Any idea ?
Here is the sound factory header and code :
#include <QSound>
class SoundFactory
{
public:
static QSound *newSound(const QString &filename, QObject *parent = 0);
};
#endif
__________________________________
#include "audio/soundfactory.h"
#ifdef Q_OS_LINUX
#include "audio/alsasound.h"
#endif
QSound *SoundFactory::newSound(const QString &filename, QObject *parent)
{
#ifdef Q_OS_LINUX
return new QAlsaSound(filename, parent);
#else
return new QSound(filename, parent);
#endif
}
And here is the QAlsaSound header and code (parts) :
class QAlsaSound : public QSound
{
public :
QAlsaSound( const QString& filename, QObject* parent=0) ;
~QAlsaSound() {};
bool initialise() ;
void play();
}
___________________________________________
#include "audio/soundfactory.h"
#include "audio/alsasound.h"
#ifdef Q_OS_LINUX
#include <alsa/asoundlib.h>
#endif
QAlsaSound::QAlsaSound( const QString& filename, QObject* parent):
QSound(filename,parent)
{
is_available = initialise();
}
bool QAlsaSound::initialise()
{
... bloody ALSA code ->gets executed when QAlsaSound is created
}
void QAlsaSound::play()
{
... further bloody ALSA code -> never gets executed when called
}
--
[ signature omitted ]
Message 2 in thread
Hi,
eb wrote:
> But when the play() function is called from outside (clickSound->play()),
> the code of the subclass is not executed.
> (when play is called from within QAlsaSound code, it works, though)
>
> Any idea ?
QSound::play isn't virtual.
Tim
--
[ signature omitted ]
Message 3 in thread
SoundFactory::newSound() returns a pointer to a QSound object, and
QSound::play() is not a virtual function.
so when you call clickSound->play() - QSound::play() is called.
if the concept is new to you, read up on virtual member functions.
Cheers,
Peter
> -----Original Message-----
> From: eb [mailto:eb5@xxxxxxxxxx]
> Sent: Friday, May 18, 2007 4:53 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: weird QSound subclassing issue
>
> Hello,
>
> This may not be a Qt issue, but rather C++. However, since it involves
> QSound, I thought I'd post here.
>
> <rant mode>
> btw, why on earth did TT *not* build QSound over Alsa
> ??????????????????????
> they do a pretty good job overall , but this is beyond my
understanding.
> </rant mode>
>
>
> Ok, I have this is my code :
>
> clickSound = SoundFactory::newSound(
> "/usr/share/myApp/sounds/click.wav" );
> clickSound->play();
>
> What it should do is create a QSound on any non linux platform, and a
> QAlsaSound [rant, rant, rant] which subclasses QSound, on Linux
>
> When the QAlsaSound gets constructed, the code within gets actually
> executed.
>
> But when the play() function is called from outside
(clickSound->play()),
> the code of the subclass is not executed.
> (when play is called from within QAlsaSound code, it works, though)
>
> Any idea ?
--
[ signature omitted ]
Message 4 in thread
Hi,
> <rant mode>
> btw, why on earth did TT *not* build QSound over Alsa ??????????????????????
> they do a pretty good job overall , but this is beyond my understanding.
> </rant mode>
That has been discussed many times on this mailing list:
* Alsa is only available on Linux,
* NAS can play over the network, just like X11 can display over the network,
* Alsa was not available when Qt was first written, and the above two issues
may be (good or bad) reasons why Qt hasn't moved from NAS to Alsa on Linux.
It's a pity NAS or some equivalent protocol is not more widely used, so that
sounds can be played over the network. Anyway, that's the way it is. I think
Qt product management is aware of this issue: maybe support for Alsa and
similar APIs on Unix platforms will make it into future versions of Qt.
--
[ signature omitted ]
Message 5 in thread
Of course, there is a simple workaround to QSound::play not being virtual.
Make your own thin wrapper class for QSound with a virtual "play" function
(call it "myplay" or something different from "play" to be safe) that calls
QSound::play by default, then derive your Alsa class from that.
Keith
**Please do not reply to me, reply to the list.**
On 05-18-2007 12:09 PM, "Dimitri" wrote:
> Hi,
>
>> <rant mode>
>> btw, why on earth did TT *not* build QSound over Alsa ??????????????????????
>> they do a pretty good job overall , but this is beyond my understanding.
>> </rant mode>
>
> That has been discussed many times on this mailing list:
> * Alsa is only available on Linux,
> * NAS can play over the network, just like X11 can display over the network,
> * Alsa was not available when Qt was first written, and the above two issues
> may be (good or bad) reasons why Qt hasn't moved from NAS to Alsa on Linux.
>
> It's a pity NAS or some equivalent protocol is not more widely used, so that
> sounds can be played over the network. Anyway, that's the way it is. I think
> Qt product management is aware of this issue: maybe support for Alsa and
> similar APIs on Unix platforms will make it into future versions of Qt.
>
> --
> Dimitri
--
[ signature omitted ]
Message 6 in thread
Well, thanks to Keith, Peter and Tim for pointing the issue.
<rant, bloody pissed rant>
Not only TT has not been wanting to implement QSound over Alsa, while Alsa
has been part of kernel since 2.4 (that is, several years from now, and
LONG before QT4), and while it had been requested soooo many times, but
coders are not even allowed to do it straightforward.
</rant, bloody pissed rant>
I'll figure out something. Sigh
--
[ signature omitted ]
Message 7 in thread
On Friday 18 May 2007 20:29, eb wrote:
> Well, thanks to Keith, Peter and Tim for pointing the issue.
>
> <rant, bloody pissed rant>
>
> Not only TT has not been wanting to implement QSound over Alsa, while Alsa
> has been part of kernel since 2.4 (that is, several years from now, and
> LONG before QT4), and while it had been requested soooo many times, but
> coders are not even allowed to do it straightforward.
>
> </rant, bloody pissed rant>
>
Does "bloody pissed" translate to "very drunk" or "not amused"? :-)
I share your frustration when Qt doesn't do something I expect it to do. And
I'm not revealing any secrets when I confirm you that the multimedia support
(read: QSound, QMovie) hasn't been highest priority in the past years.
On the other hand, it's good that there is always something to add, after all
this secures our jobs and makes them more challenging at the same time.
There's a catch, though: The pace of commercial software development
essentially boils down to resources and funding, and at any given time both
are limited.
If your company is in need for better crossplatform multimedia support, it
could work together with Trolltech and possible jointly fund the effort.
Or, if you are more an open source kind of guy you could also simply choose
to contribute code, or work with a few other guys that do. It's not that
there are no Qt-based multimedia projects out there (hint: Phonon)
Matthias
--
[ signature omitted ]
Message 8 in thread
>
> Or, if you are more an open source kind of guy you could also simply
> choose to contribute code, or work with a few other guys that do. It's not
> that there are no Qt-based multimedia projects out there (hint: Phonon)
>
Yes, I did propose my code in this list, and on TT Qt site.
Did not raise the slightest interest from TT.
A couple of OS guys got it, though.
--
[ signature omitted ]