The parent is already given to your constructor, so just store it somewhere?
Alternatively, you can use parentWidget()
The parent is already given to your constructor, so just store it somewhere?
Alternatively, you can use parentWidget()
It does not work, if I use "parentWidget()->updateChromosome()". The error says:
plot.cpp:453: error: 'class QWidget' has no member named 'updateChromosome'
my mainFrame looks like this:
mainframe.h:
Qt Code:
#include "plot.h" #include <qwt_plot_picker.h> using namespace std; { Q_OBJECT public: ...To copy to clipboard, switch view to plain text mode
mainframe.cpp:
Qt Code:
{ ui.setupUi(this); ... d_plot = new Plot(this); layout_plot->addWidget(d_plot);To copy to clipboard, switch view to plain text mode
So how to get the pointer to the mainFrame class?
My idea was to include mainframe.h into plot.h and declare there
and then store the passed pointer to it, but I have already includede plot.h into mainframe.h, so there will be conflict!
Help me please.
You just have to cast the pointer to your class.
In this case it is not possible, because I have already included the definition of class "Plot" into the header file of class "mainFrame", so that I cannot include the definition of class "mainFrame" into the header or cpp file of class "Plot"
If I however do so (#inlcude "mainframe.h" in plot.cpp) and then:
Qt Code:
mainFrame *mf = dynamic_cast<mainFrame*>(parentWidget()); mf->updateChromosome( selected_Points[i]->value(),index);To copy to clipboard, switch view to plain text mode
then I get this error:
plot.h:11: error: redefinition of 'class Plot'
plot.h:12: error: previous definition of 'class Plot'
So I must somehow trick it around, but how?
Then is your header file wrong! use something like:
Qt Code:
#ifndef PLOT_H #define PLOT_H class Plot : ... #endifTo copy to clipboard, switch view to plain text mode
You can use a forward declaration!
Qt Code:
class mainFrame; class Plot { public: Plot(mainFrame *mf = 0); //... };To copy to clipboard, switch view to plain text mode
rambo83 (26th November 2009)
Yes, you are right, Lykurg!
I have just found something about forward declaration in Google and used it in my code and it works now! Thank you very much.
best regards,
Vitali
Bookmarks