QThread and QObject
I have a problem with Qthread. I would like to run a Functie of my Serial class in a thread. And start the thread in my mainwindow class.
But when I run my application I get the following error:
- Start Thread
- QThread: Destroyed while thread is still running
- The program has unexpectedly finished.
- Allflowlift.exe exited with code -1073741819
- void MainWindow::Serial_Connect()
- qDebug() << "Start Thread";
- QThread cThread;
- Serial sSerial;
- bSerialOn = true;
Know someone maybe what I’m doing wrong?
I have now set “QThread cThread;” in my mainwindow.h
The applicatie run now but. The Thread run not the code of the Serial::Test() functie.
- void Serial::Serial_Thread_Start(QThread &cThread)
- connect(&cThread, SIGNAL(started()), this, SLOT(Test()));
- qDebug() << "Connect Thread";
- void Serial::Test()
- for(int i = 0; i < 100; i ++)
- qDebug() << "Tread" << i;