You can only create GUI elements from the main thread…
EDIT: BTW, you should call TGMsgBox *mymsgBox = new TGMsgBox(...) instead of TGMsgBox mymsgBox = new TGMsgBox(...)
Or even simpler, just call:
new TGMsgBox(gClient->GetDefaultRoot(), (TGMainFrame *)p,
"Running Thread!", "Thread is Running and waiting to terminate.",
kMBIconAsterisk, kMBOk, &retcode);
Cheers, Bertrand.
P.S. Here is a simple example, running on Windows with ROOT v5-34-00-patches. guiThread.tar.gz (1.4 KB) The instructions to build it are in the guiThread.cxx file
Thank you for your help. We were unaware that we could not create a GUI element inside a thread.
The example files you sent also helped greatly.
The reason we wanted a separate thread to pop up a gui was to have a modaless dialog pop up and update the dialog with a time. What would be the best way to create a modal-less dialog in the main GUI thread? I can easily create a thread to send a message/timer to the dialog and update the time/clock display on the modal-less gui. Just don’t know the best way to create the Modal-less dialog.
The example is enlightening, but it will be different that what we need to implement. Here is what we need to do.
We have the main GUI with a bunch of windows controls (Buttons, check boxes, endit, list boxes etc…).
In the main GUI, there will be a button we press to perform a particular multistep function. Several dialog boxes with OK/Cancel will be displayed. Each Dialog will have a text area where there is a count down timer displaying the remaining time for the step of the process were are in. Once the timer reaches 0, the user can click on OK to pop-up the next dialog with a countdown timer. This goes on for about 8 dialogs.
We did not want the dialogs popping up interfering with the main GUI thread which is why we through of poping up a GUI within a thread (now we know we can’t do it.).
Sorry, my I’m a new person to Root and not clear on what you mean by create your own Message Box.
I looked at TGMsgBox class, to see how I can create my own implementation. It’s straight forward to implement, but I just don’t see how I can update the const char *title or msg in real-time every second once MyTGMsgBox has been created. See below.
However, perhaps if I go higher in the inheritance tree to TGMainFrame or higher and create a dialog/frame, add buttons, text area and then upate the text area as time elapses. Is this what you are talking about?
Using TGMainFrame or higher to create a “Message Box”?
Here is another example (showing also the ctrl-z key handling). You should play with it and try to understand it (then you can simplify the code and adapt it to your need), I’ll be on vacation until beginning of January… guiThread2.tar.gz (4.31 KB)
Cheers, Bertrand.