QTest crashes due to "qthread destroyed while thread is still running"
-
Hello, I'm trying to run tests with QTest on an app with threads. The problem is, when my program closes, it sends the error message "qthread destroyed while thread is still running". This seems fine during normal operation but it crashes and interrupts my QTests so I'd like to get rid of it. I tried closing threads but that doesn't solve the problem or I'm doing it wrong. Here's a fraction of my code:
void MicrophoneTest::testMic()
{
int argc = 0;
char *argv[] = {};QGuiApplication app(argc, argv); XXXBackend xxx(&app); xxx.start(); QAudioFormat format; format.setSampleRate(8000); format.setChannelCount(1); format.setSampleFormat(QAudioFormat::Int16); Microphone mic(format, &xxx); mic.start(); const QList<QAudioDevice> microphones = QMediaDevices::audioInputs(); for (const QAudioDevice µ : microphones) { qInfo() << micro.description(); } mic.changeMicrophone(microphones[1].description()); mic.changeMicrophone(microphones[0].description()); QCOMPARE("1", "1"); mic.quit(); xxx.close(); app.quit();
}
QTEST_MAIN(MicrophoneTest)
-> XXXBackend is a QIODevice
-> Microphone is a QThreadLike said, the code works fine until the end where the test function ends, then I get a fatal error "qthread destroyed while thread is still running" and the QTest terminates.
-
Use a debugger, see where it crashes. Does Microphone starts another thread? If so you should properly shut them down in mic.quit()
-
Hi and welcome to devnet,
@xuwjuy1 said in QTest crashes due to "qthread destroyed while thread is still running":
QGuiApplication app(argc, argv);
That should not be part of your test code. QTest already provides an app object. See QTEST_MAIN.