Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Deadlock - Creating a QThread from the main thread
ajaynatu last edited by
I am trying to debug a situation where 2 threads have been locked on the same mutex(QMutex). The connection between the two threads is -one thread is created from another. i.e. First is the main thread( gui thread) , from which i create a another object of an user defined class. From the constructor of this object a new thread is created. Is it a wrong usage ?
@//Some part of Code:
MyMainThread *obj = new MyMainThread(); // this class inherits QWidget
//This class declaration is in another file
AnotherObjthread obj = new AnotherObjThread(this);
SomeObj *obj = new SomeObj();
Santosh Reddy last edited by
That should not be a problem.
KA51O last edited by
So you create your own main thread? Thats totally wrong. You don't need to create the main GUI thread yourself. Thats what your applications instance is already running in. Or are you not using QApplication or QCoreApplication at all? Are both MyMainThread and SomeObj subclasses of QThread, and whats AnotherObjThread? The code snippet you posted is very confussing to me. Could you please post the complete main function and the classes declarations.
tzander last edited by
MyMainThread(); // this class inherits QWidget
I think we are not talking about the same things when we talk about Threads... A QWidget can not be a thread.
Jeroentjehome last edited by
As read in the docs, you can't and shouldn't place widgets and other MainWindow stuff in a separate thread! So when you inherit QWidget, that's what your trying to do. Keep the widget in your mainwindow thread, use signal and slots or locked data sharing to fill your widget with information