Your problem is likely what anda_skoa mentions. But in addition, you are opening the file in binary, not text mode, so what do you expect to get using fprintf? And your code will also stop copying before it reaches the last column of each row as well as the last row of the table. So you need to do a little bit of error checking on the returned QTableWidgetItem pointers as well as your iteration logic.