You Are Here:

Community: Wiki

This page was last modified on 31 October 2009, at 15:41.

How To use QSound

From Forum Nokia Wiki



ID ... Creation date 17 March 2009
Platform S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition Tested on devices S60 Emulator
Category Qt for S60 Subcategory Application


Keywords (APIs, classes, methods, functions): QSound

Overview

The QSound class provides access to the platform audio facilities.QSound

Qt provides the most commonly required audio operation in GUI applications asynchronously playing a sound file. This is most easily accomplished using the static play() function.

Preconditions

Function/Property

  • Plays the sound stored in the file specified by the given filename
QSound *sound=new QSound("C://Documents and Settings//Viral//My Documents//sound//Windows XP Startup.wav");
   sound->setLoops(3);


Signal/Slots

  • Starts playing the sound specified by this QSound object.
QObject::connect(play,SIGNAL(clicked()),sound,SLOT(play()));
  • Stops the sound playing.
QObject::connect(stop,SIGNAL(clicked()),sound,SLOT(stop()));

Source File

#include <QtGui/QApplication>
#include "widget.h"
#include<QSound>
#include<QPushButton>
#include<QHBoxLayout>
#include<QWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win=new QWidget();
QHBoxLayout *lay=new QHBoxLayout();
QSound *sound=new QSound("C://Documents and Settings//Viral//My Documents//sound//Windows XP Startup.wav");//getting the audio file
sound->setLoops(3);//three times that specific audio file is played
QPushButton *play=new QPushButton("PLAY");//press button to play sound
QPushButton *stop=new QPushButton("STOP");//press to stop playing
QObject::connect(play,SIGNAL(clicked()),sound,SLOT(play()));
QObject::connect(stop,SIGNAL(clicked()),sound,SLOT(stop()));
lay->addWidget(play);
lay->addWidget(stop);
win->setLayout(lay);
win->showMaximized();
win->setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
return a.exec();
}

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
User Rating: qfnZuserE5FratingQNx4E2E0000X
RDF Facets: qfnZuserE5FtagQSxE71tE204E2E5X