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. QTest crashes due to "qthread destroyed while thread is still running"
Forum Updated to NodeBB v4.3 + New Features

QTest crashes due to "qthread destroyed while thread is still running"

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 429 Views 2 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.
  • X Offline
    X Offline
    xuwjuy1
    wrote on last edited by
    #1

    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 &micro : 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 QThread

    Like 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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a debugger, see where it crashes. Does Microphone starts another thread? If so you should properly shut them down in mic.quit()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • X Offline
        X Offline
        xuwjuy1
        wrote on last edited by
        #3

        Thanks, the XXXBackend had started something else. Correctly closed it and now the test passes (there is still some crash but only after the unit tests are finished).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved