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. Accessing functions of parent class in child class
Forum Updated to NodeBB v4.3 + New Features

Accessing functions of parent class in child class

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k 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.
  • G Offline
    G Offline
    georgecyriac989
    wrote on 15 Nov 2013, 17:18 last edited by
    #1

    @-Header.h
    class RichEditor : public QTextEdit
    {
    Q_OBJECT
    public:
    RichEditor(Datamine *parent);
    };
    class Datamine : public QMainWindow
    {
    Q_OBJECT

    public:
    Datamine(QWidget *parent = 0);
    private:
    RichEditor *textEditor;
    }

    Inside datamine.cpp
    #include header.h
    RichEditor::RichEditor(Datamine parent)//gives error expected ) before '' token--
    {
    //i wish to add connect to signals of parent and the signal I will trigger in insertfrommimedata(not shown)
    }

    Datamine::Datamine(QWidget *parent)
    : QMainWindow(parent)
    {

    }@

    What is shown about is only a small part of code.
    I am trying to override insertfrommimedata of texteditor and call a function of datamine from within it. THe problem is that I am unable to access richeditors parent(Datamine) to access these functions
    I am trying to call the constructor of richeditor with datamine as the class and error says expect ) before * token
    I can't move richeditor class to below datamine since in the private of Datamine I have defined RichEditor *texteditor .
    I am learning QT this is my first project...please help. Any snippets on accessing child from parent is appreciated

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on 15 Nov 2013, 19:03 last edited by
      #2

      Is there really no semicolon after the ending brace of class Datamine in header.h?

      Are there really no quotes around "header.h" in file datamine.cpp?

      Both of these things could cause compiler problems.

      Also, before the class definition of RichEditor, add the line:
      class Datamine;
      and google "forward declaration".

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 15 Nov 2013, 21:30 last edited by
        #3

        Hi,

        You are preparing yourself for some troubles. Child widget should not know anything about their parent. It's creating a tight coupling that generally ends in maintenance nightmare. You should use signals and slots to communication between the two. The parent widget should be responsible for the connections, but not the child.

        Have a look at the various examples and demos you can find within Qt's sources. The documentation itself provides also a lot of them.
        One chapter you should start with is "Signals and Slots"

        Happy learning !

        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
        • G Offline
          G Offline
          georgecyriac989
          wrote on 16 Nov 2013, 03:23 last edited by
          #4

          Thank you scottR forward declaration solved it.

          1 Reply Last reply
          0

          1/4

          15 Nov 2013, 17:18

          • Login

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