Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:57:37+00:00 2026-05-27T11:57:37+00:00

I have two custom QML elements for audio, one for playing music (and extends

  • 0

I have two custom QML elements for audio, one for playing music (and extends the QML Audio element) and one for playing sound effects (which extends QML’s SoundEffect element).

I am able to play background music with no problem, but when I try to play a sound effect, the interface freezes for a couple of seconds (the music keeps playing) and then when it unfreezes, I get the Windows error sound.

Here is what I have (the music has a similar architecture):

MySoundEffect.qml

Loader {
   id: container
   source: "MobilitySoundEffect.qml"

   property bool  valid: item !== null
   property real  audioVolume: 1.0
   property int   loops: 1

   function initialise() {
      if(valid) {
         item.volume = container.audioVolume
         item.loops = container.loops
      }
   }

   function play(filename) { if(valid) item.play(filename); }
   function stop() { if(valid) item.stop(); }
   onLoaded: container.initialise()
   onAudioVolumeChanged: if(valid) item.volume = audioVolume;
}

MobilitySoundEffect.qml

Item {
   id: container

   property url   source: ""
   property real  volume: 1.0
   property int   loops: 1

   function play(filename) {
      if (settings.isFxOn()) {
         source = filename;
      }
   }

   function stop() { soundEffect.stop(); }
   SoundEffect {
      id: soundEffect
      source: container.source
      volume: container.volume
      loops:  container.loops
      onStatusChanged: if (Audio.Loaded == status) play();
   }
}

And here is how I register them (trimmed for brevity):

main.qml

Rectangle {
   id: main
   MyAudio {
      id: music
   }
   MySoundEffect {
      id: soundEffects
   }
   PageStack {
      id: pageStack

      Component.onCompleted: {
         pageStack.push(Qt.resolvedUrl("pages/IntroPage.qml"));
      }
   }
}

Finally, this is how I call them to play music or a sound effect:

soundEffects.play("file://assets/audio/click.ogg");  
music.play("file://assets/audio/menu.mp3");

Again, music plays fine, sound effects don’t. And, as far as I tested, it has nothing to do with the filetype. I couldn’t get wav, mp3 or off to play.

My setup is Windows 7, QtSDK 7.4.7, Symbian 1.1.

Under Microsoft Visual Studio Compiler 9.0 I get the freezing and the error sound, but under MinGW 4.4, there is no freeze or error sound, yet, still no sound effect.

Update

I have now moved all my assets (qml, audio, txt, etc) into a QResource file and now neither sound effect nor music is playing. Whenever I try to play music I get the following in the output:

qrc file :/audio/menu.ogg
Size 353349
Sequential 0

I really need to fix this, so I have started a bounty. Please help.

Thank you in advance.

Solution (more like a work around)

Indeed, QSound cannot play sounds from a resource and I cannot make the SoundEffect element to work. So my work around is the following:

I use the QML Audio element to play background music (which support fade in/fade out) and I created a SoundEffects class in C++ using Phonon to play the sound effects.

It seems to work fine, so I’m not touching it again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:57:38+00:00Added an answer on May 27, 2026 at 11:57 am

    I think the QML Audio element is a wrapper around QSound, which cannot access sound files from Qt Resource File System (Mentioned in the Document)Note that QSound does not support resources. This might be fixed in a future Qt version.. Regarding the Windows warning/error sound, I guess, playing the sound effect may be blocking the main UI thread.

    It may also be caused, if QSound cannot play two audio files simultaneously. You can try QtMultimedia or Phonon if there are some limitations in QSound class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two ItemsControls, one a ListView, and one a custom control I am
I have a IEnumerable. I have a custom Interval class which just has two
I have two custom entites, Product and ProductType, linked together in many-to-one relationship. Product
I have two types of custom handhelds which are similar, but slightly different, each
I have a webform with two custom validators: One to validate that a string
I have a custom spinner that uses two custom views, one for the drop
I have a custom user control UserProfileLink on which I have two basic string
I have two routes in my area, one custom and one default fallback route,
I have two custom methods for a model manager in Django. One of them
I've got an odd situation. Basically, I have two custom bindings which are used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.