Buffer Overrun using Qt Threads and Signals

后端 未结 1 1414
萌比男神i
萌比男神i 2021-01-24 13:14

I have to downgrade a project from QT5 to QT4 and get a weird buffer overrun error when doing so. Here\'s my code:

I create a QThread like so:

thread =         


        
相关标签:
1条回答
  • 2021-01-24 13:51
    void MainWindow::threadFinished() {
        reader = NULL;
        delete thread;
        thread = NULL;
    }
    

    Deleting the thread directly in the slot is not advised. You should use the deleteLater function.

    thread->deleteLater();
    

    However, you've already setup the thread to be deleted in the connection

    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    

    So you're now trying to delete it twice!

    As for the buffer-overrun, I suspect something has corrupted memory before the error has occurred.

    0 讨论(0)
提交回复
热议问题