[wxWidgets] how to unfroze the GUI while the event is running?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[wxWidgets] how to unfroze the GUI while the event is running?
Hello, I have to make a very simple GUI for my C++ mathematical model.
Basically I just need a wxTextContr window that display the output of my model as it is produced.
The problem is that is is display at the end of the event call (when the model end, sometimes after hours), while I need it in real-time.
I am completelly new to GUI programming, so I think what I wrote is completelly ridicolous...
I would seriously appreciate on GUI programming strategies to improve my small GUI ;-).
This is what I wrote:
Code:
class
regmasapp : public wxApp
{
public:
virtual bool OnInit();
};
class
regmasFrame : public wxFrame
{
public:
void OnRun( wxCommandEvent& event );
wxTextCtrl* logAreaBox;
[...]
}
void
regmasFrame::OnRun( wxCommandEvent& WXUNUSED( event ) )
{
MainProgram* myProgram;
myProgram = new MainProgram( this);
myProgram->run();
}
class MainProgram{
private:
regmasFrame* GUI;
public:
MainProgram( regmasFrame* GUI_h);
~MainProgram();
void run();
};
and finally...
MainProgram::MainProgram(regmasFrame* GUI_h):GUI(GUI_h)
{
}
void
MainProgram::run(){
[...]
GUI->logAreaBox->AppendText(wxT("Stampa qualcosa\n"));
[...]
}
If I understand you correctly then you are computing data which takes a long time; yet you want to display results as they happen rather than at the end of the computation.
Use two threads one for the gui and one for the computation, have data passing from the maths thread into a threadsafe queue and display the results in that thread.
This allows the gui to be responsive whilst still computing the data, tho I would give a higher priority to the the non gui thread.
If I understand you correctly then you are computing data which takes a long time; yet you want to display results as they happen rather than at the end of the computation.
Use two threads one for the gui and one for the computation, have data passing from the maths thread into a threadsafe queue and display the results in that thread.
yes, that's correct.
Can you raccomand me a tutorial on this point?
(I was thinking that the thread division was just made automatically by wxWidgets when calling events)
My knowledge of wxWidgets is very minimal(almost nothing lol), so you may be correct. If its a thread tutorial you are looking for then I would recommend Posix thread tut
My knowledge of wxWidgets is very minimal(almost nothing lol), so you may be correct. If its a thread tutorial you are looking for then I would recommend Posix thread tut
thanks.. I really think there is a "wxWay" to use threads in a wxWidget application, but yr generic tutorial is very nice (just too flashing banners on that site :-(( )
wxWidgets has a thread class you can use, wxThread.
iirc there is an entire chapter dedicated to threads in a book that is available for free from the prentice hall website. i cant think of the name of the book though..
wxWidgets has a thread class you can use, wxThread.
iirc there is an entire chapter dedicated to threads in a book that is available for free from the prentice hall website. i cant think of the name of the book though..
I am really, really lost on all of this. here I read:
Quote:
Before starting an MT application (or starting to add MT features to an existing one) it is worth asking oneself if there is no easier and safer way to implement the same functionality. Of course, in some situations threads really make sense (classical example is a server application which launches a new thread for each new client), but in others it might be a very poor choice (example: launching a separate thread when doing a long computation to show a progress dialog). Other implementation choices are available: for the progress dialog example it is far better to do the calculations in the idle handler or even simply do everything at once but call wxWindow::Update() periodically to update the screen.
That's more or less my case... a long computation where I need just to display things sequentially. Yes, I would also like to use the capability to pause,resume,stop, but this isn't really so necessary.
...or even simply do everything at once but call wxWindow::Update() periodically to update the screen.
...which cou...
I personally see this as the correct method to acheive what you want and is the way many guis work. Their comment I would see as a word of warning that everything may not go as you wish, if you don't have an understanding of threads and the benefits they do or do not give.
On the other hand if you do not want to use threads, then you would have to stop the computation at some point to display results and then continue...
If it was to be run on a dual core cpu, I would try splitting the computation into threads
[edit]misread the comment about wxWindow::Update().
This is an option.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.