Deadlock - Creating a QThread from the main thread
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();
That should not be a problem.
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.
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.
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