Thats exactly your problem. The easiest way to solve this problem is, that you only call gui functions from within your thread that created the gui. In general calling gui functions from within a thread that didn't created the gui is not a good practice and often causes such problems. The are ways to do this, but its too long ago, that I developed C++. Maybe somebody can you explain how to do such calls.
Greetings Covean