Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: Easy way to process something on a thread?

Yes, it involves defining a new class.  I don't think you can declare them in-line (like a lambda-function), but I may be wrong.

 

The only reason you may want to use QThreads over pthreads is that a QThread can do signals and slots, etc, whereas a pthread is in no way bound to the internal Qt stuff, so it's going to be limited in how it interacts with other Qt objects.

 

I gave an equivalent example to Martin's using pthreads in your class.  His example used an external friend function which is unnecessary if you use a static member function as the thread entry point.

 

Cheers,

Sean

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: Easy way to process something on a thread?

[ Edited ]

also, I'm not sure how much simpler you need things to get than:

 

class MyThread : public QThread {
public:
   void run();
};

MyThread::run() { .... }

If you wanted to make a do-anything thread, you could just define MyThread(function_pointer) which would take care of running any code you want.

 

If you instead want to use pthreads, then you have to take care of thread life-cycle management yourself.

 

Cheers,

Sean

Highlighted
Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Easy way to process something on a thread?

Yea, QThread has start() and run(). One of the cascade samples (don't remember which) has the app class extending QThread instead of QObject. Which I don't endorse, but its one way to not have a second subclass if you go that direction.