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

QSound error in thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.7k Views
  • 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
    alecs26
    wrote on last edited by
    #1

    Hello,

    I am trying to play a sound in a non-qt thread:

    QSound::play(":/button20.wav");
    

    I receive this error:
    QObject: Cannot create children for a parent that is in a different thread.

    Any ideas ?

    Thanks,

    Alex

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      Can you create an instance and play that?

      #include <QSound>
      ...
      QSound button20Sound(":/button20.wav");
      button20Sound.play();
      
      1 Reply Last reply
      0
      • A Offline
        A Offline
        alecs26
        wrote on last edited by alecs26
        #3

        Thank you for your answer.
        With your method, the error is not there anymore.

        However, I don't hear the sound. I hear it when I play the file outside the thread (in the main).

        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