QObject :: moveToThread: widgets cannot be moved to a new thread

My IDE Qt 5.0.1 Linux Platform

I have a problem installing a widget in a window. (My opinion)

this is my main.cpp →

int main(int argc, char *argv[]) { QApplication a(argc, argv); QThread cThread; MainWindow w; w.doSetup(cThread); w.moveToThread(&cThread); cThread.start(); if(cThread.isRunning()) { qDebug() << " Thread is Running..."; } w.show(); return a.exec(); } 

this is the doSetup () method ->

 void MainWindow::doSetup(QThread &mainThread) { QObject::connect(&mainThread, &QThread::started, this, &MainWindow::activeLoopMainC); } 

I checked the signal slot mechanism and it works.

slot method →

 void MainWindow::activeLoopMainC() { qDebug() << " Signal-Slot structure working successfully.."; mainThreadProc((void*)(instAddr)); } 

I call a function from my main.c with this method of slots.

There is no problem with working codes in debugging. But my window is empty. there is only a frame.

i error message appears: QObject :: moveToThread: widgets cannot be transferred to a new thread

How can I solve this problem?

Thank you in advance for your answers.

+4
source share
1 answer

You cannot move widgets to another thread - for the user interface to respond, Qt must do all the GUI work inside the main thread.

If you have background work, move the background worker to a different thread, not to the user interface.

+8
source

Source: https://habr.com/ru/post/1497257/


All Articles