Using a TThread to call a method

I’m building a GUI, in which a method to read a file needs to be called every second, on the second. I tried using just a TTimer, but the method’s finite running time causes the TTimer to fall behind. Thus, I am trying to implement this using a TThread. I have tried following the example in the User’s guide, but the code won’t compile:

/sample.C:40: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say `&MyMainFrame::PrintStuff' ./sample.C:40: error: converting from `void*(MyMainFrame::*)(void*)' to `void (*)(void*)'

Would someone be able to tell me what I’m doing wrong, here? I’ve tried dropping the & from the funciton call, to make it no longer called as a pointer, but then the data type is all wrong (and more complicated than my limited understanding of C++).

A stripped-down version of my code is attached. Thanks!
sample.C (1.63 KB)


I don’t really understand what you’re trying to do, but anyway, please take a look at your (slightly :wink:) modified macro.

sample.C (1.85 KB)

Is it necessary that the method be static?

The documentation in the class index is ambiguous on this point. In my full program, I am hoping to use the method to update and draw some histograms in the main frame of the GUI.

Please take a look at this page:
It says: [quote]Create a thread. Specify the function or static class method to be executed by the thread and a pointer to the argument structure.[/quote]
Non-static methods have an implicit argument: the this pointer (a pointer to the object the function is called on); it is not the case for free functions or static methods.


In the three instances of the constructor description below that one, the word “static” is omitted. This is what led to my confusion.

Thanks for your help, I’ll try to find a work-around.

You could try something like this:

[code]MyMainFrame::MyMainFrame(const TGWindow p,UInt_t w,UInt_t h) :
TGMainFrame(p,w,h), timer(0), thread(0)

thread = new TThread(“thread”, PrintStuff, (void
) this);

void *MyMainFrame::PrintStuff(void *arg)
MyMainFrame *main = (MyMainFrame *)arg;

– Bertrand.

[quote=“bellenot”]You could try something like this:

– Bertrand.[/quote]

That’s exactly what came to mind. Thanks again for your help, I’m off to write some Get and Set functions for my histograms.