[Interest] type casting 5 levels down no error but not proper
Konstantin Tokarev
annulen at yandex.ru
Tue Apr 24 14:06:35 CEST 2012
24.04.2012, 15:58, "Sujan Dasmahapatra" <sdh at lmwindpower.com>:
> I have my mainwindow which is QMainWindow the parent of all my other classes. I am type casting upwards from 5 levels down using reinterpret_cast, to access the mainwindow to display message using statusBar(), but when type casting it's not giving error but when accessing mainwindow->statusBar() it's crashing.
1. Don't use reinterpret_cast. Use qobject_cast, dynamic_cast, or (if you are absolutely sure what you are doing) static_cast
2. In this case use qobject_cast and check if returned value in each invocation is non-zero. Zero means that you guess about pointer type is wrong.
--
Regards,
Konstantin
More information about the Interest
mailing list