views:

121

answers:

2

I have a threadSafe method that gets called by multiple threads. Is there a way to know which thread called it?

+1  A: 

If you need it, you could add a threadId parameter, and let it thread pass it to the method

Samuel Carrijo
yeah I was aware of that but I wanted to minimize user intervention so as to not let anyone call the function in the wrong way, now user has to know if its a mainthread or qthread call. So it would have to add that parameter only when working in the qthread
yan bellavance
+3  A: 

Well, you know the thread that calls the method, and by extension the same thread will be active inside that method call. You can just call QThread::currentThread() to get this.

Chris Dennett
actually there is no method called getCurrentThread but the there is a static in QThread called currentThread...ill try it.
yan bellavance
Ah yes, sorry -- I thought the original post said Java :) I got currentThread wrong in Java too, it is in fact Thread.currentThread() here too, ugh :) Anyway, glad my post helped; looks like the two APIs have similarly named classes / methods anyway :)
Chris Dennett