samedi 26 juin 2021

Using wxLogMessage to Log into wxTextCtrl from different implementation Files - wxWidgets

Hi i am outputting/logging messages using wxLogMessage() into a wxTextCtrl. For the textctrl i have created a separate class called MyLog that contains a wxTextCtrl and it uses something like:

wxTextCtrl *textCtrl = new wxTextCtrl(...);
wxLog::SetActiveTarget(new wxLogTextCtrl(textCtrl));

Then i have another class called MyFrame and from MyFrame constructor i can use wxLogMessage("My First log message"); to log into the textCtrl. This works correctly and the message is successfully logged into the textCtrl. But the problem is that i have many other classes as well like MyPanel, Calculate, Compress and i want to use wxLogMessag() command from inside these classes to log into the same textCtrl that i created earlier. But when i use wxLogMessage("Second message"); from inside any of these other classes the message is not logged into the textCtrl and instead a message dialog box opens up having the same message we passed. So my questions are:

  1. How can i log messages into the textCtrl that i created inside class MyLog from inside the other classes.
  2. I looked into the samples directory of wxWidgets and there in the events folder. And in one of the example files called gestures.cpp they have used the statement delete wxLog::SetActiveTarget(new wxLogTextCtrl(textCtrl)); instead of using wxLog::SetActiveTarget(new wxLogTextCtrl(textCtrl));. So which one of the above should i use? Will wxWidgets handle the destruction by its internal mechanism or should i write delete explictly while using the command wxLog::SetActiveTarget(new wxLogTextCtrl(textCtrl)); in the constructor of the class MyLog?
  3. Also, as i mentioned, i have several implementation files and each one of them has a different role. For example. the Calculate class do some calculation and stores the result into some object. Similarly for other classes as well. Now my question is as my application starts using MyApp and then MyFrame classes which are part of the gui process, should i create a separate thread for the work of another classes. That is the gui will be in the main thread and then i can create a separate thread which will do all the non-gui related task like calculating something etc. Or should i use only a single thread. If i need to create a separate thread for the non-gui part then how can i log messages from those other classes(that are in the other thread) into the textCtrl that i created in the MyLog class which is in the main gui thread?

Aucun commentaire:

Enregistrer un commentaire