Results 1 to 5 of 5

Thread: QSound being partial

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Red face QSound being partial

    I use a simple QSound::play . I created a playAlarm() function to start it, but all I get when I click the button is the annoying Vista sound "tã"!

    here is the header:
    Qt Code:
    1. #ifndef MYQTAPP_H
    2. #define MYQTAPP_H
    3.  
    4. #include "ui_myqtapp.h"
    5. #include <QString>
    6. #include <QSound>
    7.  
    8. class myQtApp : public QWidget, private Ui::myQtAppDLG
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. myQtApp(QWidget *parent = 0);
    14. void playFor();
    15.  
    16. public slots:
    17. //void getPath();
    18. void doSomething();
    19. void clear();
    20. void about();
    21. void showTime();
    22. void playAlarm();
    23. void stopAlarm();
    24.  
    25. private:
    26. QTime currTime;
    27. QString currTimeText;
    28. };
    29.  
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 

    here is the cpp:

    Qt Code:
    1. myQtApp::myQtApp(QWidget *parent)
    2. {
    3. setupUi(this);
    4. connect( pushButton_do, SIGNAL( clicked() ), this, SLOT( doSomething() ) );
    5. connect( pushButton_clear, SIGNAL( clicked() ), this, SLOT( clear() ) );
    6. connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
    7. connect( startButton, SIGNAL( clicked() ), this, SLOT( playAlarm() ));
    8. connect( stopButton, SIGNAL( clicked() ), this, SLOT( stopAlarm()));
    9.  
    10. QTimer *timer = new QTimer(this);
    11. connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
    12. timer->start(1000);
    13. showTime();
    14. }
    15.  
    16.  
    17. void myQtApp::playAlarm(){
    18. QSound::play("alarms/guitar.wav");
    19. }
    To copy to clipboard, switch view to plain text mode 

    but when I put that on the main function, the wav file works:

    Qt Code:
    1. myQtApp::myQtApp(QWidget *parent)
    2. {
    3. setupUi(this);
    4. // QSound::play("alarms/guitar.wav");
    5. connect( pushButton_do, SIGNAL( clicked() ), this, SLOT( doSomething() ) );
    6. connect( pushButton_clear, SIGNAL( clicked() ), this, SLOT( clear() ) );
    7. connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
    8. connect( startButton, SIGNAL( clicked() ), this, SLOT( playAlarm() ));
    9. connect( stopButton, SIGNAL( clicked() ), this, SLOT( stopAlarm()));
    10.  
    11. QTimer *timer = new QTimer(this);
    12. connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
    13. timer->start(1000);
    14. showTime();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Any idea why? Any help really epreciated! Thanks!
    Last edited by wysota; 13th March 2009 at 01:30. Reason: Changed [qtclass] to [code]

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSound being partial

    It looks right to me. What happens when you use an absolute path to the wav file?

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSound being partial

    It looks normal, no compiler errors, but no sound comes when I call the function. Only that "tã" sound .

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSound being partial

    Does it not work even if you put the sound on your root drive and call:
    Qt Code:
    1. QSound::play("c:/guitar.wav");
    To copy to clipboard, switch view to plain text mode 

    I'm asking because it seems like it might not be finding the file from the relative path.

  5. #5
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Talking Re: QSound being partial

    Oooooops..... My bad! Just spotted the problem... I put a absolute path to it and now its all working. I had misspelled the audio file.

Similar Threads

  1. QSound and embedded resources
    By baray98 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2017, 13:38
  2. QThread doent work for QSound
    By anafor2004 in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2008, 16:00
  3. playing mp3 file with QSound
    By highlightsong in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2008, 09:24
  4. Is QSound all there is?
    By ad5xj in forum Newbie
    Replies: 4
    Last Post: 1st September 2007, 01:31
  5. Replies: 1
    Last Post: 7th July 2006, 10:14

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.