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. QAudioOutput vs QTimer strange behaviour
Forum Updated to NodeBB v4.3 + New Features

QAudioOutput vs QTimer strange behaviour

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 4 Posters 3.7k 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 abarmotov

    @mzimmers i thought, that in singles thread qt app is not possible that slot interrupts another slot - they are serialized in execution

    so maybe here bug with QAudioOutput somehow, because if i comments out "new QAudioOutput" - there is no "HMMM" in output

    full source here: https://github.com/a132791/TestQt3

    mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #14

    @abarmotov evidently, you're right - calls to slots are queued and don't interrupt one another.

    I'm running Qt 6.4 and made a couple changes to your slot. Program works as expected.

    void MainWindow::on_pushButton_clicked()
    {
        if (slotIsRunning_)
            qDebug() << "HMMM";
    
        slotIsRunning_ = true;
    //    QAudioFormat format;
        QAudioOutput* audioPlayer_ = new QAudioOutput();
        qDebug() << "QAudioOutput created";
    
        QThread::sleep(1); // some work
    
        delete audioPlayer_;
        qDebug() << "QAudioOutput deleted";
        slotIsRunning_ = false;
        QTimer::singleShot(std::rand()%50, this, &MainWindow::on_pushButton_clicked);
    }
    

    The code wouldn't compile with the QAudioOutput c'tor as coded.

    A 1 Reply Last reply
    0
    • A abarmotov

      @wrosecrans but how it set "true" ?

      sorry - in first post the slotIsRunning_ is set to false in constructor

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #15

      @abarmotov said in QAudioOutput vs QTimer strange behaviour:

      but how it set "true" ?

      You set it to true in the slot, so I don't understand the problem.
      On first slot call "HMMM" will not be printed but slotIsRunning_ will be set to true, so on second slot call you will print "HMMM"...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • mzimmersM mzimmers

        @abarmotov evidently, you're right - calls to slots are queued and don't interrupt one another.

        I'm running Qt 6.4 and made a couple changes to your slot. Program works as expected.

        void MainWindow::on_pushButton_clicked()
        {
            if (slotIsRunning_)
                qDebug() << "HMMM";
        
            slotIsRunning_ = true;
        //    QAudioFormat format;
            QAudioOutput* audioPlayer_ = new QAudioOutput();
            qDebug() << "QAudioOutput created";
        
            QThread::sleep(1); // some work
        
            delete audioPlayer_;
            qDebug() << "QAudioOutput deleted";
            slotIsRunning_ = false;
            QTimer::singleShot(std::rand()%50, this, &MainWindow::on_pushButton_clicked);
        }
        

        The code wouldn't compile with the QAudioOutput c'tor as coded.

        A Offline
        A Offline
        abarmotov
        wrote on last edited by
        #16

        @mzimmers said in QAudioOutput vs QTimer strange behaviour:

        I'm running Qt 6.4 and made a couple changes to your slot.

        does it means what in 5.12 the QAudioOutput is broken ?

        mzimmersM 1 Reply Last reply
        0
        • jsulmJ jsulm

          @abarmotov said in QAudioOutput vs QTimer strange behaviour:

          but how it set "true" ?

          You set it to true in the slot, so I don't understand the problem.
          On first slot call "HMMM" will not be printed but slotIsRunning_ will be set to true, so on second slot call you will print "HMMM"...

          A Offline
          A Offline
          abarmotov
          wrote on last edited by
          #17

          @jsulm said in QAudioOutput vs QTimer strange behaviour:

          You set it to true in the slot, so I don't understand the problem.

          the problem is that slot interrupted in SINGLE thread app - that not expected by me
          is it documented somewhere ?

          1 Reply Last reply
          0
          • A abarmotov

            @mzimmers said in QAudioOutput vs QTimer strange behaviour:

            I'm running Qt 6.4 and made a couple changes to your slot.

            does it means what in 5.12 the QAudioOutput is broken ?

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #18

            @abarmotov said in QAudioOutput vs QTimer strange behaviour:

            does it means what in 5.12 the QAudioOutput is broken ?

            Doubtful. According to the docs for 5.15, your constructor looks good (I notice you don't initialize your QAudioOutput object, but that shouldn't matter for this exercise).

            I'm more suspecting there's something wrong with re-using your slot as the argument to the QTimer::singleShot call. When that's commented out, it seems to work fine, right?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              abarmotov
              wrote on last edited by
              #19

              @mzimmers said in QAudioOutput vs QTimer strange behaviour:

              When that's commented out, it seems to work fine, right?

              no, HMMM is still there on second click
              but i tested only on 5.12.8

              jsulmJ 1 Reply Last reply
              0
              • A abarmotov

                @mzimmers said in QAudioOutput vs QTimer strange behaviour:

                When that's commented out, it seems to work fine, right?

                no, HMMM is still there on second click
                but i tested only on 5.12.8

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #20

                @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                A mzimmersM 3 Replies Last reply
                0
                • jsulmJ jsulm

                  @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                  A Offline
                  A Offline
                  abarmotov
                  wrote on last edited by
                  #21

                  @jsulm said in QAudioOutput vs QTimer strange behaviour:

                  Still don't get what the issue is...

                  the mouse click on button "should not" interrupt any running slot, but must be queued in qt event loop in single thread app
                  am i wrong ?

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                    A Offline
                    A Offline
                    abarmotov
                    wrote on last edited by
                    #22

                    @jsulm said in QAudioOutput vs QTimer strange behaviour:

                    so on second button press slotIsRunning_ is true

                    slotIsRunning_ is set to false at end of slot - that the point

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                      mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #23

                      @jsulm said in QAudioOutput vs QTimer strange behaviour:

                      @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                      He sets slotIsRunning_ at the start of the slot, but then sets it to false towards the end.

                      jsulmJ 1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        @jsulm said in QAudioOutput vs QTimer strange behaviour:

                        @abarmotov Why do you think so? You wrote: "then press on button two times". So, as I explained: on the first button press you set slotIsRunning_ to true, so on second button press slotIsRunning_ is true and you print "HMMM". So, nothing is interrupted. Still don't get what the issue is...

                        He sets slotIsRunning_ at the start of the slot, but then sets it to false towards the end.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #24

                        @mzimmers Yeah, did not notice that.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          abarmotov
                          wrote on last edited by
                          #25

                          Any thoughts on why this is happening?

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            abarmotov
                            wrote on last edited by
                            #26

                            i found it:

                            QPulseAudioOutput::~QPulseAudioOutput()
                            {
                                close();
                                disconnect(m_tickTimer, SIGNAL(timeout()));
                                QCoreApplication::processEvents(); // THAT STRING BREAKS EVENT LOOP
                            }
                            
                            jsulmJ 1 Reply Last reply
                            0
                            • A abarmotov

                              i found it:

                              QPulseAudioOutput::~QPulseAudioOutput()
                              {
                                  close();
                                  disconnect(m_tickTimer, SIGNAL(timeout()));
                                  QCoreApplication::processEvents(); // THAT STRING BREAKS EVENT LOOP
                              }
                              
                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #27

                              @abarmotov said in QAudioOutput vs QTimer strange behaviour:

                              THAT STRING BREAKS EVENT LOOP

                              It does not "break" event loop, it just tells event loop to check and handle events if there are any.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              A 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @abarmotov said in QAudioOutput vs QTimer strange behaviour:

                                THAT STRING BREAKS EVENT LOOP

                                It does not "break" event loop, it just tells event loop to check and handle events if there are any.

                                A Offline
                                A Offline
                                abarmotov
                                wrote on last edited by
                                #28

                                @jsulm
                                but this is the way my slot is called a second time, while that slot in middle on execution
                                this behavior is not obvious when deleting QAudioOutput

                                jsulmJ 1 Reply Last reply
                                0
                                • A abarmotov

                                  @jsulm
                                  but this is the way my slot is called a second time, while that slot in middle on execution
                                  this behavior is not obvious when deleting QAudioOutput

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #29

                                  @abarmotov Why did you add processEvents at all there?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  A 1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @abarmotov Why did you add processEvents at all there?

                                    A Offline
                                    A Offline
                                    abarmotov
                                    wrote on last edited by
                                    #30

                                    @jsulm it ain't me )
                                    QPulseAudioOutput - this is qt source code

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • A abarmotov

                                      @jsulm it ain't me )
                                      QPulseAudioOutput - this is qt source code

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #31

                                      @abarmotov Ah, right. Would be interesting to know why it was added - doesn't look correct to me and causes the issue you have.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      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