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. what it means by 'Qobject has a parent'

what it means by 'Qobject has a parent'

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.7k 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.
  • J Offline
    J Offline
    JadeN001
    wrote on last edited by
    #1

    moveToThread() will fail if the QObject has a parent according to QtDocument.
    i don't know what it means by "QObject has a parent".
    how can i identify that any QObject has a parent or not

    K 1 Reply Last reply
    0
    • Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      Hi,

      QObject takes an optional parent in its constructor.

      QObject(QObject *parent = nullptr)
      

      You probably created an instance of a class inheriting from QObject, and pass "this" as the parent. In this case just remove the "this" from your code

      //MyObject *o = new MyObject(this);
      MyObject *o = new MyObject;
      

      By the way you can check if an object has a parent using QObject::parent().

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Its normally the first parameter in constructor.

        https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

        as you see here for the worker class

        QThread* thread = new QThread;
        Worker* worker = new Worker(); <<< no parent given
        worker->moveToThread(thread);
        
        1 Reply Last reply
        3
        • J JadeN001

          moveToThread() will fail if the QObject has a parent according to QtDocument.
          i don't know what it means by "QObject has a parent".
          how can i identify that any QObject has a parent or not

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @JadeN001

          A lot of Qt objects are inheriting from QObject and allow to set a parent, which will be handed down to QObject.
          Either you set a parent to take care of handling the object or you leave it as a null pointer (no parent).

          See more details

          Vote the answer(s) that helped you to solve your issue(s)

          J 1 Reply Last reply
          4
          • K koahnig

            @JadeN001

            A lot of Qt objects are inheriting from QObject and allow to set a parent, which will be handed down to QObject.
            Either you set a parent to take care of handling the object or you leave it as a null pointer (no parent).

            See more details

            J Offline
            J Offline
            JadeN001
            wrote on last edited by JadeN001
            #5

            @koahnig i am new in qt.which type of object(s) can be called as a QObject. As u have mention Qt objects. what is Qt objects?
            When a QObject receives a queued signal or a posted event, the slot or event handler will run in the thread that the object lives in. what QObejct means in this sentence.

            K 1 Reply Last reply
            0
            • J JadeN001

              @koahnig i am new in qt.which type of object(s) can be called as a QObject. As u have mention Qt objects. what is Qt objects?
              When a QObject receives a queued signal or a posted event, the slot or event handler will run in the thread that the object lives in. what QObejct means in this sentence.

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @JadeN001

              Here is an example for QWidget:
              0_1525428310083_87c24edf-df22-49d5-8b9a-3c7da81ed770-image.png

              The rest you find in the documentation for each class.

              In this case QWidget is directly inheriting from QObject and it is inherited by lot of other classes.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              1

              • Login

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