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. Why some classess are QObject?

Why some classess are QObject?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 332 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    Hello,

    Could you tell me why some classess in their constructor have parent?

    For example: QTimer(QObject *parent = nullptr).

    I understand why parent is important in QWidget. When I have QDialog and I would like to have QPushButton on it I can set that QPushButton as child that QDialog. And when I move QDialog I move QPushButton too. And when I set QPushButton's position to (0,0), this position is not a global position, but position in QDialog.

    But why have to set parent in QTimer? Only because of I don't have to delete that QTimer when I delete QDialog? Or maybe something else?

    KroMignonK 1 Reply Last reply
    0
    • T TomNow99

      Hello,

      Could you tell me why some classess in their constructor have parent?

      For example: QTimer(QObject *parent = nullptr).

      I understand why parent is important in QWidget. When I have QDialog and I would like to have QPushButton on it I can set that QPushButton as child that QDialog. And when I move QDialog I move QPushButton too. And when I set QPushButton's position to (0,0), this position is not a global position, but position in QDialog.

      But why have to set parent in QTimer? Only because of I don't have to delete that QTimer when I delete QDialog? Or maybe something else?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @TomNow99 said in Why some classess are QObject?:

      Or maybe something else?

      For example signals/slots?

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        @KroMignon Yeah, I forget about it :D

        jsulmJ 1 Reply Last reply
        0
        • T TomNow99

          @KroMignon Yeah, I forget about it :D

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @TomNow99 https://doc.qt.io/qt-5/objecttrees.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4

          • Login

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