I have a problem with pushing elements to a QList
when iterating over it.
Let's see example code below:
typedef struct
{
int a[2];
} myType;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QList<myType> list;
// Create list
for( int i = 0; i < 1000; i++)
{
list << (myType){ i, i };
}
int iteration = 0;
for ( auto &i : list )
{
i.a[1] = 5;
if ( ! (i.a[0] % 10) )
{
list.push_back( (myType){ 7, 7 } );
}
iteration++;
}
w.show();
return a.exec();
}
When I debug the code I have a segmentation fault (i
got value 0xfeeefeeefeeefeee
):
What is the reason?