Threading and messages

I have a class which does downloading in a separated thread. For example:

[code]class FileManager:public Thread, public MessageListener
void* result;
virtual void handleMessage (const Message& message);
void run();

void FileManager::run()
StatusMessage* msg= new StatusMessage(SuccessStat);
postMessage( msg);

and a UI component, which runs thread to download a file:

class SomeComponent: public Component, public MessageListener { void runLoading(); virtual void handleMessage (const Message& message); }
What I want is to receive a message from FileManager inside handleMessage
How should I bind FileManager and SomeComponent to be able to handle messages? Something related to MessageManager ?


//corrected code

It sounds like you want to pass arbitrary messages from one thread to another?

Here is my message class:

class StatusMessage: public Message { int m_status; public: StatusMessage(int stat); ~StatusMessage(void); int status(){return m_status;} };
And I want to notify Main UI thread that donwloading is completed and to do something like

statusLabel->setText("Downloading completed", false);

So make the thread post a message to the thing you want to notify… (?)

That is my question. How to post it exactly to my component?

That is my question. How to post it exactly to my component?[/quote]

With MessageListener::postMessage() !

I do it like

but cannot receive it in

Then you’re posting it to the wrong place.

I post it in the thread I want to receive a message from.
I’ve found this thread
It appears that MessageListener cannot listen to messages from another thread.

[quote=“acid”]I do it like
postMessage( msg);

but cannot receive it in

you need to do


It appears that i need to pass pointer to the component to the 2nd thread and then it works.
Thank you.