PDA

View Full Version : QSound as member of a class



martin83
5th April 2011, 12:35
Hi, it´s my first post in the forum. I´m a newbie and I think the question is more about C++ than Qt.

Well, I have a class "Alarmer" inherits from QWidget; it's a popup. I need to add, as a member of Alarmer, a QSound instance, to have scope of visibility from all the member functions of Alarmer. I try to use it to call play() and stop() from different member functions.
So, I add this line to the .h file:

QSound alarm;
But I don't know how to initialize it in the constructor of "Alarmer". I try with different options without result.

I hope you can help me,

MartÃ*n

mcosta
5th April 2011, 13:21
If you know the filename to pass it you can write



Alarmer::Alarmer (): alarm (fileName, this)
{
...
}


other option is



Alarmer::Alarmer (const QString& fileName): alarm (fileName, this)
{
...
}

martin83
5th April 2011, 19:45
Thanks mcosta, I will try it later but you let me know how to initialize member objects calling its member constructors in that way.

Thanks again