QThread and QObject
Hello
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
- The program has unexpectedly finished.
- Allflowlift.exe exited with code -1073741819
the Mainwindow
- void MainWindow::Serial_Connect()
- {
- qDebug() << "Start Thread";
- QThread cThread;
- Serial sSerial;
- sSerial.Serial_Thread_Start(cThread);
- sSerial.moveToThread(&cThread);
- cThread.start();
- bSerialOn = true;
- }
The Serial.cpp:
- {
- }
- {
- connect(&cThread, SIGNAL(started()), this, SLOT(Test()));
- }
- void Serial::Test()
- {
- qDebug() << "Tread";
- }
The Serial.h
- {
- Q_OBJECT
- public:
- private slots:
- void Test();
- signals:
- };
Know someone maybe what I’m doing wrong?
6 replies
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.
The Serial.cpp
- {
- connect(&cThread, SIGNAL(started()), this, SLOT(Test()));
- qDebug() << "Connect Thread";
- }
- void Serial::Test()
- {
- for(int i = 0; i < 100; i ++)
- {
- qDebug() << "Tread" << i;
- }
- }
I have declare the thread in my MainWindow.
- namespace Ui {
- class MainWindow;
- }
- {
- Q_OBJECT
- public:
- ~MainWindow();
- private:
- QThread cThread;
- Ui::MainWindow *ui;
- };
You must log in to post a reply. Not a member yet? Register here!




