Key press event in a templated class
-
The difficulty for me is, this helper class would need a reference to an instance of a template class. Can I do that without the helper class being templated? The only kludgey way I can
see to do this is to use a helper class and an interface. I'm new at C++ templates so
maybe I'm missing something.Here's some pseudo-code.
This is what I wish I could do, but can't because of the q_object/template thing:
@
template <class T>
class Foo {constructor {
QTableView table...
connect(table, doubleClicked, doubleClicked)
}slot doubleClicked {
T t = ... calculated from QModelIndex
handler.handle(t)
}Handler<T> handler; // member
}
@This is my hack. How can I do this better?
@
class Interface { public: callBackIndex(QModelIndex) }class Helper {
Q_OBJECT
slot doubleClicked { callback.callbackIndex(QModelIndex); }
Interface callback; // member
}
template <class T>
class Foo : public Interface {constructor {
QTableView table...
connect(table, doubleClicked, helper.doubleClicked)
}callbackIndex {
T t = ... calculated from QModelIndex
handler.handle(t)
}Helper helper (this); // member
Handler<T> handler; // member}
@
The handler is being passed into Foo and Foo has a couple other templated members as well.
I just don't know how to pass in a reference to Foo in Helper without Helper being templated as well.
If I try to pass it in as a pointer with no template parameter it is an error: Helper::Helper(Foo* foo)