Qt-interest Archive, February 2008
How to use QSound?
Message 1 in thread
Dear all,
Please help me detect the following code for which QSound is unavaliable.
#include <QApplication>
#include <QObject>
#include <QSound>
#include <iostream>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QSound word("./newjwing.wav");
std::cout << QSound::isAvailable() << std::endl;
word.play();
return app.exec();
}
When I make it, everything is ok. But, there's no sound nor text output
at all. The result is :
rr@linux-ezwe:~/workspace/test> make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB
-DQT_CORE_LIB -DQT_SHARED
-I/usr/local/Trolltech/Qt-4.3.3/mkspecs/linux-g++ -I.
-I/usr/local/Trolltech/Qt-4.3.3/include/QtCore
-I/usr/local/Trolltech/Qt-4.3.3/include/QtCore
-I/usr/local/Trolltech/Qt-4.3.3/include/QtGui
-I/usr/local/Trolltech/Qt-4.3.3/include/QtGui
-I/usr/local/Trolltech/Qt-4.3.3/include -I. -I. -I. -o main.o main.cpp
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.3.3/lib -o test main.o
-L/usr/local/Trolltech/Qt-4.3.3/lib -lQtGui
-L/usr/local/Trolltech/Qt-4.3.3/lib -L/usr/X11R6/lib -lpng -lSM -lICE
-pthread -pthread -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama
-lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread
-lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
rr@linux-ezwe:~/workspace/test> ./Sound
rr@linux-ezwe:~/workspace/test> ./Sound
rr@linux-ezwe:~/workspace/test>
Why is it? How can I use the QSound to make some .wav files sound?
Thank you.
Kermit
--
[ signature omitted ]
Message 2 in thread
On Sunday 24 February 2008 04:01:59 pm Kermit Mei wrote:
> int main(int argc,char *argv[])
> {
> QApplication app(argc,argv);
> QSound word("./newjwing.wav");
> std::cout << QSound::isAvailable() << std::endl;
> word.play();
> return app.exec();
> }
It looks like that is not the code you are running (because there is no
standard output shown in your run.
Perhaps it will work better if you start the event loop first:
#include <QApplication>
#include <QObject>
#include <QMessageBox>
#include <QSound>
#include <iostream>
class MySoundPlayer : public QWidget
{
public:
MySoundPlayer()
{
setWindowTitle( "My Sound Player" );
QMessageBox *msgBox = new QMessageBox( this );
msgBox->setText( QString( "QSound %1 available").arg(
QSound::isAvailable()? "is":"is not" ) );
msgBox->setWindowTitle( "QSound Status");
msgBox->show();
QSound word("./kiss.wav");
word.play();
};
};
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
MySoundPlayer player;
player.show();
return app.exec();
}
Also, on my system (Linux) isAvailable() returns false - the documentation
says that it returns true on Windows. However it might be your Qt doesn't
actually have sound support. So I don't know if the code I've provided works
or not.
Good luck.
Brad
--
[ signature omitted ]
Message 3 in thread
Brad Hards wrote:
> On Sunday 24 February 2008 04:01:59 pm Kermit Mei wrote:
>
>> int main(int argc,char *argv[])
>> {
>> QApplication app(argc,argv);
>> QSound word("./newjwing.wav");
>> std::cout << QSound::isAvailable() << std::endl;
>> word.play();
>> return app.exec();
>> }
>>
> It looks like that is not the code you are running (because there is no
> standard output shown in your run.
>
> Perhaps it will work better if you start the event loop first:
> #include <QApplication>
> #include <QObject>
> #include <QMessageBox>
> #include <QSound>
> #include <iostream>
>
> class MySoundPlayer : public QWidget
> {
> public:
> MySoundPlayer()
> {
> setWindowTitle( "My Sound Player" );
> QMessageBox *msgBox = new QMessageBox( this );
> msgBox->setText( QString( "QSound %1 available").arg(
> QSound::isAvailable()? "is":"is not" ) );
> msgBox->setWindowTitle( "QSound Status");
> msgBox->show();
> QSound word("./kiss.wav");
> word.play();
> };
> };
>
> int main(int argc,char *argv[])
> {
> QApplication app(argc,argv);
> MySoundPlayer player;
> player.show();
> return app.exec();
> }
>
> Also, on my system (Linux) isAvailable() returns false - the documentation
> says that it returns true on Windows. However it might be your Qt doesn't
> actually have sound support. So I don't know if the code I've provided works
> or not.
>
> Good luck.
>
> Brad
>
>
Thank you,Brad. But "QSound is not available". How to make it work on
Linux? Or can somebody tell me how to make a sound hint to the
users instead of it?
--
[ signature omitted ]
Message 4 in thread
On mandag den 25. Februar 2008, Kermit Mei wrote:
> Thank you,Brad. But "QSound is not available". How to make it work on
> Linux? Or can somebody tell me how to make a sound hint to the
> users instead of it?
You need to install alsa and the alsa devel packages and make sure Qt is
compiled to use them.
Bo.
--
[ signature omitted ]
Message 5 in thread
Hi,
> On mandag den 25. Februar 2008, Kermit Mei wrote:
>> Thank you,Brad. But "QSound is not available". How to make it work on
>> Linux? Or can somebody tell me how to make a sound hint to the
>> users instead of it?
>
> You need to install alsa and the alsa devel packages and make sure Qt is
> compiled to use them.
Actually the Network Audio System (NAS) and NAS devel packages need to be
installed.
--
[ signature omitted ]
Message 6 in thread
Dimitri wrote:
> Hi,
>
>> On mandag den 25. Februar 2008, Kermit Mei wrote:
>>> Thank you,Brad. But "QSound is not available". How to make it work on
>>> Linux? Or can somebody tell me how to make a sound hint to the
>>> users instead of it?
>>
>> You need to install alsa and the alsa devel packages and make sure Qt
>> is compiled to use them.
>
> Actually the Network Audio System (NAS) and NAS devel packages need to
> be installed.
>
> --
> Dimitri
Hi, my friends, I did install the alsa and the NAS, but "QSound is not
available" yet. Why?
How does the other program make sounds in Linux? Are there other ways?
Thank you!
--
[ signature omitted ]
Message 7 in thread
Hi,
> Hi, my friends, I did install the alsa and the NAS, but "QSound is not
> available" yet. Why?
Here are possible reasons:
* NAS is not working properly.
* Qt has not been built with sound support. Have you built Qt with NAS
support? Are NAS development packages installed?
--
[ signature omitted ]