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. QProcess running aplay
Qt 6.11 is out! See what's new in the release blog

QProcess running aplay

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k 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.
  • G Offline
    G Offline
    garyeholmes
    wrote on last edited by
    #1

    Hi,

    I'm using qt4.7.4 on an embedded Linux target.

    I'm trying to add a sound when my touch panel is activated.

    When a button is clicked I call the following:

    @if (QFile::exists(s))
    {
    cout << "close" << endl;
    soundProcess->close();
    cout << "start" << endl;
    soundProcess->start("aplay "+s);
    soundProcess->waitForFinished();
    cout << "done" << endl;
    }

    @

    soundProcess is a class variable of type QProcess* and is opened on class instantiation.

    I have tried far more than above, this is the simplest.

    This works fine for a varying number of key clicks with about 1ms reported between "close" and "start" and 220ms between "start" and "done" (i.e. the length of the sound) until at some point I start getting about 30 seconds between "start" and "done" - which obviously kills my gui.

    Anyone got any idea what might be going on - or any better ideas to achieve this?

    I thank you in advance.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You can use QProcess::startDetached which runs in a separate process and returns immediately.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Why do you wait for it to finish at all? If it's just a sound for touch feedback then you don't need to establish an input/output channel or keep track of the process. Wouldn't it be better with a "fire and forget" style, i.e. "QProcess:startDetached":http://qt-project.org/doc/qt-5/qprocess.html#startDetached ?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          garyeholmes
          wrote on last edited by
          #4

          Hi,

          msue - thanks for reply. Tried startDetached and it returns immediately as you suggested. After a number of 'plays' though I then get the error 'audio open error: Device or resource busy'.

          In fact Chris, I started with your approach as this is what I want to end up with. I put the 30 second 'hang' down to the sound system being busy or something so thought I'd try waiting for it to complete as a test.

          No nearer a solution yet but thanks...

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            The problem might lie with the default termination behaviour of the "aplay" program. You could experiment with some of its options (e.g. -d).

            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