[Qt-interest] Connecting slots to virtual objects

Sean Harmer sean.harmer at maps-technology.com
Fri Jul 2 13:27:52 CEST 2010


On Friday 02 July 2010 12:22:18 Thiago Macieira wrote:
> Em Sexta-feira 2. Julho 2010, às 13.59.50, Dirk Neumann escreveu:
> > Now I want to connect to mySignal() inside the constructor of B. An
> > expression like
> 
> Inside constructors, virtual calls to "this" are not virtual. So you cannot
> call the pure virtual B::myA() from inside B::B().
> 
> Sorry, you need to redesign your approach. This is how C++ works.

One possible simple solution to this is to have your ctor use a singleshot 
timer with a 0 timeout value to call an init() type slot that then makes the 
connection for you. This way your object's vtable will exist when you make the 
connect() call.

Sean




More information about the Qt-interest-old mailing list