PDA

View Full Version : Inheritance qt



Cat
5th November 2015, 03:37
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


class MainWindow : public QMainWindow
{
Q_OBJECT
QWidget *centralWidget;
public:
MainWindow (QWidget* parent=0);
QwtPlot *funPlot;
}
class OptionPlot : public MainWindow
{
Q_OBJECT
public:
OptionPlot (QWidget* parent=0);
...
}

.cpp


...
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent) {
funPlot = new QwtPlot(this);
}
OptionPlot:OptionPlot(QWidget *parent):
MainWindow(parent) {
}
...
// implementation of methods MainWindow class and OptionPlot further

main.cpp


...
QApplication app(argc, argv);
MainWindow *window = new MainWindow;
OptionPlot *option1 = new OptionPlot;

window->setPlot();
window->setGrid();
window->createMenu();

option1->setCurve();
option1->addPoints();
option1->setCheckBox();
...
return app.exec();

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

anda_skoa
5th November 2015, 08:46
You are creating two windows and there is no code indicating that either has any checkboxes or graphics.

Cheers,
_

Cat
9th November 2015, 07:58
Why? I use methods of the option1 class: addPoints() for drawing graphics and setCheckBox().

anda_skoa
9th November 2015, 08:11
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,
_

Cat
9th November 2015, 08:26
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.

anda_skoa
9th November 2015, 11:26
Window created with only methods of "window" object

You have two windows: "window" and "option1"
You are calling different methods on each.



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,
_