There are couple of things in your code which may cause you problems, (may not be the problem which you see now)
1. Disable sorting (if enabled) on the QTableWidget when inserting rows, and enable back when insertion and item setting is done.
2. There is no check on m (detstatsList.size()) for it to be multiple of 4 (a row with few empty columns)
Bookmarks