Nightfox
16th August 2009, 13:46
Hi
I have two classes that both are sub-classed from Qt objects. The first is myMainWindow that inherits from QMainWindow and the second is myWidget that inherits from QWidget.
In myMainWindow I have defined a model (QAbstractTableModel) that I want to access from myWidget. So what I do is this
In the myMainWindow header I define the class
(mymainwindow.h)
class myMainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QAbstractTableModel *model;
myWidget *mywidget;
}
In the implementation file I initiate the objects
(mymainwindow.cpp)
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
mywidget = new myWidget(this) ;
}
The problem is when I want to access the model from myMainWindow through myWidget
(mywidget.cpp)
myWidget:: myWidget (QWidget *parent) : QWidget(parent)
{
QAbstractItemModel *model =parent->model;
}
Is it not possible to access the model object through the parent? I’ve been looking for an example the shows this but so far no luck.
Any good suggestions out there? Thanks!
I have two classes that both are sub-classed from Qt objects. The first is myMainWindow that inherits from QMainWindow and the second is myWidget that inherits from QWidget.
In myMainWindow I have defined a model (QAbstractTableModel) that I want to access from myWidget. So what I do is this
In the myMainWindow header I define the class
(mymainwindow.h)
class myMainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QAbstractTableModel *model;
myWidget *mywidget;
}
In the implementation file I initiate the objects
(mymainwindow.cpp)
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
mywidget = new myWidget(this) ;
}
The problem is when I want to access the model from myMainWindow through myWidget
(mywidget.cpp)
myWidget:: myWidget (QWidget *parent) : QWidget(parent)
{
QAbstractItemModel *model =parent->model;
}
Is it not possible to access the model object through the parent? I’ve been looking for an example the shows this but so far no luck.
Any good suggestions out there? Thanks!