Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QSound example
Qt 6.11 is out! See what's new in the release blog

QSound example

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 4 Posters 19.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndreiDutu
    wrote on last edited by
    #1

    I am trying to do an app and I want to use QSound.
    Unfortunately I can’t get it to work. I read the "documentation":http://doc.qt.nokia.com/latest/qsound.html but they don’t explain what’s the most important part: where do you store the audio file and how to declare it.
    Does anybody have a simple example that uses QSoud?

    A button that makes a sound when you press it or something like that.

    Thanks.

    Smile :)

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

      I would use a resource file and store my sounds in there and just use

      @
      void MainWindow::on_pushButton_clicked()
      {
      QSound sound(":/sounds/notification");
      sound.play();
      /*
      OR
      QSound::play(":/sounds/notification");
      */

      }
      @
      Where ":/" = the notification that u use a resource file.
      "/sounds/" = the prefix you made in your resource file.
      "notification" = the alias u gave the .wav file u use.
      Instead of using an alias u also can give the filename like "sound.wav", but i think its "better" to use an alias. That way u only have to change your resource file when u want to use an other sound for the notification.
      When u dont want to use a resourcefile just pass the whole "path to sound file" to the play function

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kkrzewniak
        wrote on last edited by
        #3

        From the doc:
        Note that QSound does not support resources. This might be fixed in a future Qt version.

        Me, Grimlock, not "nice dino". ME BASH BRAINS!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AndreiDutu
          wrote on last edited by
          #4

          That’s why I asked for a working example. I tried with the resource file, didn’t worked.
          I tried with the path to the file but here I get stuck. What is the relative path to file?

          How can I define the path so it works when I will compile for mobile ?

          Smile :)

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kkrzewniak
            wrote on last edited by
            #5

            for Symbain just:
            @soundFiles.sources = sounds*.wav
            DEPLOYMENT += soundFiles@
            to Your project file
            and i code
            @QSound *sound = new QSound("some.wav",this);@

            Me, Grimlock, not "nice dino". ME BASH BRAINS!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              danilocesar
              wrote on last edited by
              #6

              Is it Symbian or Windows?

              If it's linux it's not going to work.

              <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
              Software Engineer

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AndreiDutu
                wrote on last edited by
                #7

                In the end i will compile the app for Symbian. Right now i am just tring in the Qt SDK (on windows) but with no succes.

                Smile :)

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kkrzewniak
                  wrote on last edited by
                  #8

                  If your running it with QtSimulator, have You tried copping the sound files to the apps simulator folder? And I don't remember if simulator has sound output. QFile::exists might be helpful for debugging if the sound file gets found.

                  Me, Grimlock, not "nice dino". ME BASH BRAINS!

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AndreiDutu
                    wrote on last edited by
                    #9

                    I got it to work, thanks guys.

                    And i confirm, the sound doesn't work in the simulator, only on the symbian device. Good thing i had my C7 to test on. :)

                    Smile :)

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved