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. [SOLVED]Access fathers public function from children
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Access fathers public function from children

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.9k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Crackeraki
    wrote on last edited by
    #1

    i have made in child pointer of father and try to call one public function of him. But it tells me that QWidget(father type) dont have that function. In which way i can call fathers public function?
    Small example of what i have in childen class:
    @
    QWidget *keepFather = parent;
    ...
    keepFather->setWindowFlags(keepFather->windowFlags() ^ Qt::WindowStaysOnTopHint); //That's working normaly because that function is from QWidget
    ...
    keepFather->changeThings(8); //That's not working, it's from public function of father's pointer
    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Buckets
      wrote on last edited by
      #2

      if the class is derived from a QWidget the QWidget would be the parent (father) class, so it doesn't inherit any of the properties of the child class.

      edit:: In order to resolve your problem you would have to cast the keepFather pointer to that of the child class, or declare keepFather as a pointer to the child class.

      ba ba ba
      ba na na na

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Crackeraki
        wrote on last edited by
        #3

        Yes, i was thinking something like that, but still working on making pointer of father class. I dont see how can i make include parent class to build pointer of parent object.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          To avoid having such coupling, you should rather use signals and slots to update the parent content based on the child actions. So the child doesn't need to know it's parent class.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Crackeraki
            wrote on last edited by
            #5

            Ok i think i have to search there, thx. How to set post Solved?
            [quote author="SGaist" date="1379965124"]Hi,

            To avoid having such coupling, you should rather use signals and slots to update the parent content based on the child actions. So the child doesn't need to know it's parent class.[/quote]

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That is done by editing your first post, there you can update the title :)

              Happy coding !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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