I have a newbie question about passing data from a worker thread to the main.
In the examples on-line I found how to attach an integer to an event in a worker thread and how to get it in the event handler of the main thread:
Code: Select all
//in worker thread:
wxThread::ExitCode wrkThr::Entry()
{
for (int n=0; n<100; n++)
{
this->Sleep(500);
//notify the main thread
wxCommandEvent e( wxEVT_COMMAND_TEXT_UPDATED, NUMBER_UPDATE_ID );
//pass some data along the event, a number in this case
e.SetInt(n);
frmParent->GetEventHandler()->AddPendingEvent(e);
}
return 0;
}
...
//in main thread:
void frmMain::OnNumberUpdate(wxCommandEvent& e)
{
//setting value in text box
tbDisp->SetValue(std::to_string(e.GetInt()));
}
So the main work done by two (probably standard) functions: SetInt(n) and GetInt().
But what if I need to pass two integers? Or an integer and a float? Or even more than two values? I do not need a variable size data, it always be the same type.
Say, if, for example, I use a struct:
Code: Select all
struct strData
{
int int1;
int int2;
float f1;
}
Thank you in advance!