Results 1 to 6 of 6

Thread: Inheritance qt

  1. #1
    Join Date
    Oct 2015
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Inheritance qt

    Hello. In my program is the class MainWindow, which is inherited from QMainWindow. Is it possible to create another class, which would be the heir to MainWindow. I want to create objects by these classes in main.cpp and call methods. Just when I attempted such an implementation methods successor from MainWindow not performed.

    .h

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4. QWidget *centralWidget;
    5. public:
    6. MainWindow (QWidget* parent=0);
    7. QwtPlot *funPlot;
    8. }
    9. class OptionPlot : public MainWindow
    10. {
    11. Q_OBJECT
    12. public:
    13. OptionPlot (QWidget* parent=0);
    14. ...
    15. }
    To copy to clipboard, switch view to plain text mode 

    .cpp

    Qt Code:
    1. ...
    2. MainWindow::MainWindow(QWidget *parent):
    3. QMainWindow(parent) {
    4. funPlot = new QwtPlot(this);
    5. }
    6. OptionPlot:OptionPlot(QWidget *parent):
    7. MainWindow(parent) {
    8. }
    9. ...
    10. // implementation of methods MainWindow class and OptionPlot further
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. ...
    2. QApplication app(argc, argv);
    3. MainWindow *window = new MainWindow;
    4. OptionPlot *option1 = new OptionPlot;
    5.  
    6. window->setPlot();
    7. window->setGrid();
    8. window->createMenu();
    9.  
    10. option1->setCurve();
    11. option1->addPoints();
    12. option1->setCheckBox();
    13. ...
    14. return app.exec();
    To copy to clipboard, switch view to plain text mode 

    The window is created, the grid and the menu too, but CheckBoxes and graphics isn't. What is a mistake of that realization?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance qt

    You are creating two windows and there is no code indicating that either has any checkboxes or graphics.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2015
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheritance qt

    Why? I use methods of the option1 class: addPoints() for drawing graphics and setCheckBox().

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance qt

    Then you forgot to post the code of those methods.

    You also did not post the code that shows the two windows.
    Instead you wrote "The window is created" which does not tell us which of the two windows or if both are created, etc.

    Cheers,
    _

  5. #5
    Join Date
    Oct 2015
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheritance qt

    Window created with only methods of "window" object . And I used QDebuged for finding more information. It showed that methods of option1 are done but they are not apply to the window. At least I had some info messages.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance qt

    Quote Originally Posted by Cat View Post
    Window created with only methods of "window" object
    You have two windows: "window" and "option1"
    You are calling different methods on each.


    Quote Originally Posted by Cat View Post
    And I used QDebuged for finding more information. It showed that methods of option1 are done but they are not apply to the window.
    Since you have two windows, saying "the window" is not enough. Which window?
    And if you have determined that the methods are being called, maybe if you are not seeing what you are expecting then the problem is that the methods are wrong?

    Cheers,
    _

Similar Threads

  1. Inheritance
    By Atomic_Sheep in forum General Programming
    Replies: 5
    Last Post: 17th December 2013, 08:17
  2. C++ inheritance
    By yyiu002 in forum Newbie
    Replies: 3
    Last Post: 29th June 2010, 11:38
  3. inheritance
    By steiner in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2007, 20:17
  4. inheritance
    By mickey in forum General Programming
    Replies: 11
    Last Post: 28th September 2007, 21:54
  5. QSA and inheritance
    By jwintz in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 14:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.