This assumes that the layout used in the QFileDialog actually is QGridLayout. You force the pointer to be QGridLaout * (because of the static cast), and then you use it inside the loop without checking to see if it actually -is- a pointer to QGridLayout and not null. That's a recipe for a crash if something ever changes in QFileDialog.QGridLayout *layout = static_cast<QGridLayout*>(this->layout());
Better is to use qobject_cast< QGridLayout * >, and then check that the return value is not null before blindly using the pointer. Using an "assert( layout != 0 )" will let you trap it while debugging so you can fix it. Using an "if ( layout != 0 )" conditional clause will prevent your app from crashing (although it won't work properly).
Bookmarks