QAudioOutput vs QTimer strange behaviour
-
@wrosecrans but how it set "true" ?
sorry - in first post the slotIsRunning_ is set to false in constructor
@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"... -
@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.
-
@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"... -
@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 ?
@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?
-
@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@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...
-
@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...
-
@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...
-
@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...
@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.
-
@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.
-
i found it:
QPulseAudioOutput::~QPulseAudioOutput() { close(); disconnect(m_tickTimer, SIGNAL(timeout())); QCoreApplication::processEvents(); // THAT STRING BREAKS EVENT LOOP }
@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.
-
@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.
-
@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@abarmotov Why did you add processEvents at all there?
-
@abarmotov Why did you add processEvents at all there?
-
@abarmotov Ah, right. Would be interesting to know why it was added - doesn't look correct to me and causes the issue you have.