Hi,
i wonder what is a better practice of passing pointers to childwidgets (if their is anything like a common good practice
) of this two possibilities: Passing the Baseclass or MyClass?
I have a MainWindow and need to pass a pointer to subclass of QSqlTableModel to a childwidget:
mainwindow.cpp
MyQSqlTableModel *tm = new MyQSqlTableModel;
ChildWidget *cw = new ChildWidget( this );
cw->setTableModel( tm );
MyQSqlTableModel *tm = new MyQSqlTableModel;
ChildWidget *cw = new ChildWidget( this );
cw->setTableModel( tm );
To copy to clipboard, switch view to plain text mode
1. childwidget.cpp
{
m_model = qobject_cast<MyQSqlTableModel *>(model);
m_model->doSomething();
void ChildWidget::setTableModel( QAbstractItemModel *model )
{
m_model = qobject_cast<MyQSqlTableModel *>(model);
m_model->doSomething();
To copy to clipboard, switch view to plain text mode
2. childwidget.cpp
void ChildWidget::setTableModel( MyQSqlTableModel *model )
{
m_model = model;
m_model->doSomething();
void ChildWidget::setTableModel( MyQSqlTableModel *model )
{
m_model = model;
m_model->doSomething();
To copy to clipboard, switch view to plain text mode
I have seen both and wonder what the difference is and what the better approach might be.
Bookmarks