Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Deadlock - Creating a QThread from the main thread
QtWS25 Last Chance

Deadlock - Creating a QThread from the main thread

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ajaynatu
    wrote on last edited by
    #1

    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:

    void main()
    {
    MyMainThread *obj = new MyMainThread(); // this class inherits QWidget
    }

    //This class declaration is in another file
    class Someobj
    {
    SomeObj()
    {
    }
    StartAnotherObjThread()
    {
    AnotherObjthread obj = new AnotherObjThread(this);
    obj->start();
    }
    }

    MyMainThread()
    {
    SomeObj *obj = new SomeObj();
    obj->StartAnotherObjThread();
    }@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Santosh Reddy
      wrote on last edited by
      #2

      That should not be a problem.

      SS

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tzander
          wrote on last edited by
          #4

          @
          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.

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            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
            Greetz

            Greetz, Jeroen

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved