Thanks for your help. I'd be happy to show you my code:

My *.h file

Qt Code:
  1. class MyWidget : public QWidget
  2. {
  3. ..........
  4. public:
  5. void function1();
  6. void function2();
  7.  
  8. private:
  9. QStringList list2;
  10. ..........
  11. }
To copy to clipboard, switch view to plain text mode 

There's nothing in the constructor for the QStringList.
My main *.cpp file:

Qt Code:
  1. void MyWidget::function1(){
  2. QStringList list; // declared and filled with data, everything OK here
  3. .....................
  4. i =4;
  5. QStringList list2(list);
  6. for (int j =0; j <list.size(); j++)
  7. {
  8. list2[j] = list[i];
  9. i +=1;
  10. if (i>=list.size()) i=0;
  11. }
  12.  
  13. function2();
  14. }
  15.  
  16. void MyWidget::function2(){
  17. // contains my C code to test if the right thing happened
  18. //nothing is written into the output file
  19. // but it works if I put this code inside function1()
  20. //so I know there are no logic or syntax error
  21. FILE *my;
  22. if ((my=fopen("output.txt","w")) == 0) {exit(1);}
  23. char filename2[70];
  24. for (int k =0; k <list2.size(); k++){
  25. strncpy(filename2, list2[k].toLocal8Bit().constData(), 70);
  26. fprintf(my, "%s\n", filename2);
  27. }
  28.  
  29. fclose(my);
  30. }
To copy to clipboard, switch view to plain text mode