Qt-interest Archive, December 2007
QTableView and non-virtual slots
Message 1 in thread
hi everybody,
i just encountered that QTableView::columnCountChanged(int, int) does
not work as i expected, or that i'm missing
sth. here:
i have a class which inherits QTableView and reimplements the slot
columnCountChanged(int, int), which should be called
whenever the number of sections of the horizontal header changes.
however, if i do sth. like:
QAbstractItemModel* model = createMyModel();
MyTableView* view = new MyTableView;
view->setModel(model);
model->insertColumn(0);
then my implementation of columnCountChanged is not called, although
the model emits columnsInserted which is translated
to a signal sectionCountChanged by the horizontal header in QTableView
which in turn is connected to columnCountChanged.
however, some other reimplemented slots like dataChanged work fine.
now i just discovered that the mentioned slots are no virtual
functions in QTableView, may that be the reason that my version of
the method is not invoked by QTableView? if so, is there a way to
achieve the invokation of MyTableView::columnCountChanged
if it was connected to signals in QTableView?
thanks in advance,
julian
--
[ signature omitted ]
Message 2 in thread
Hi,
There's a standard trick involved with non-virtual slots: Disconnect the
connection to the base class and connect to the subclass instead:
disconnect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
connect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
This makes sure your slot is called instead of the one in the base class. You
simply do this after the rest of the system is set up. And it's an evil hack
you can use in many different areas of Qt whenever you feel like being up to
serious mischief :-)
Bo.
On lørdag den 1. December 2007, Julian Heinrich wrote:
> hi everybody,
>
> i just encountered that QTableView::columnCountChanged(int, int) does
> not work as i expected, or that i'm missing
> sth. here:
>
> i have a class which inherits QTableView and reimplements the slot
> columnCountChanged(int, int), which should be called
> whenever the number of sections of the horizontal header changes.
> however, if i do sth. like:
>
> QAbstractItemModel* model = createMyModel();
> MyTableView* view = new MyTableView;
> view->setModel(model);
> model->insertColumn(0);
>
> then my implementation of columnCountChanged is not called, although
> the model emits columnsInserted which is translated
> to a signal sectionCountChanged by the horizontal header in QTableView
> which in turn is connected to columnCountChanged.
> however, some other reimplemented slots like dataChanged work fine.
>
> now i just discovered that the mentioned slots are no virtual
> functions in QTableView, may that be the reason that my version of
> the method is not invoked by QTableView? if so, is there a way to
> achieve the invokation of MyTableView::columnCountChanged
> if it was connected to signals in QTableView?
>
> thanks in advance,
> julian
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 3 in thread
> There's a standard trick involved with non-virtual slots:
> Disconnect the
> connection to the base class and connect to the subclass instead:
>
> disconnect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
> connect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
Are you sure this makes a difference?
the connect() call only takes QObject pointers so it shouldn't make a
difference if it's been called in the base class or the derived class.
If it does make a difference, i'd be interested in how this works :)
Cheers,
Peter
--
[ signature omitted ]
Message 4 in thread
On Dec 3, 2007 12:50 PM, Peter Prade <prade@xxxxxxxxxxx> wrote:
> > There's a standard trick involved with non-virtual slots:
> > Disconnect the
> > connection to the base class and connect to the subclass instead:
> >
> > disconnect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
> > connect(sender, SIGNAL(...), myTableView, SLOT(columnCo...));
>
> Are you sure this makes a difference?
> the connect() call only takes QObject pointers so it shouldn't make a
> difference if it's been called in the base class or the derived class.
>
> If it does make a difference, i'd be interested in how this works :)
even if it worked, i still wouldn't know which signals the slot was connected to
by the base class, would i? i mean i want to change the behaviour of the table
whenever the column count changes without having to know where the signals
came from. however, for now i'm ok with reconnecting the signals i know of to
my implementation of the slot.
well, the problem is that i may be missing some signals...
--
[ signature omitted ]