I try to figure out in which C++ GUI toolkit (+stdlib+libc) it would be easiest to implement such a useful function in a normal command-line application:
void ShowStringWindow(string& s) {
// ...
}
ShowStringWindow should display a window with an editable box containing string s.
It should return immediately, so the main thread can continue.
Notes:
I would be very grateful for a working code, but that is not necessary to be useful.
To do this with Qt, you need to:
After the "exec" function returns, you need to:
There are a few ways you can update data from the main thread.
One way would be to use signals/slots with queued connection type. Using this, the UI thread updates the value. Easing the impact on the main thread. However, note that if the value update rate is too high, like 2000 times per second, you might want to change to polling the value. To do that, you might find QTimer helpful.
Updating data to the main thread should be somewhat easier, just lock the mutex and insert the value. At this point, you could check if the value that we previously got from the main thread is still the current value in the main thread. You did state that it doesn't change, but i'd not trust that :)
I hope this is sufficient. We used this to create a Qt based error dialog for a console program.