Results 1 to 3 of 3

Thread: QSound as member of a class

  1. #1
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded

    Default QSound as member of a class

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSound as member of a class

    If you know the filename to pass it you can write

    Qt Code:
    1. Alarmer::Alarmer (): alarm (fileName, this)
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 

    other option is

    Qt Code:
    1. Alarmer::Alarmer (const QString& fileName): alarm (fileName, this)
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded

    Default Re: QSound as member of a class

    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

Similar Threads

  1. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  2. Replies: 4
    Last Post: 29th May 2010, 12:56
  3. A class member has ran away?!
    By MIH1406 in forum Newbie
    Replies: 4
    Last Post: 24th August 2009, 23:21
  4. QSound class features problem
    By MarkoSan in forum Qt Programming
    Replies: 8
    Last Post: 20th December 2007, 14:21
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.