[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends

d3fault d3faultdotxbe at gmail.com
Tue Oct 23 22:28:55 CEST 2012


Thank you Alan, I've fixed the comment to say sibling.


On 10/22/12, Bo Thorsen <bo at fioniasoftware.dk> wrote:
> Now I'm getting annoyed. You're the one spreading misinformation here. I
> mentioned the pure computation as one of the cases where I prefer
> subclassing. But that of course doesn't mean you can't do it in other ways.
>

You're right, I was mainly focusing on your pure computation argument
in my response. Thought you were arguing that moveToThread couldn't do
it. ("emitting progress signals can take it off the list" -- what??
meh don't bother responding, it's pointless)

But anyways I've been following the [higher level] topics in this
thread and now I'm thinking the example in the .zip needs a complete
rewrite haha.

Here, I'm about to contradict my earlier self:

In order to have both the constructor and destructor run on the
thread, would it be a good idea to do something like this?
run()
{
	UserObject obj; //ideally this would be a template passed in to some
custom QThread implementation, but it's important to note that it is
allocated on the stack
	emit readyForConnections(&obj); //Would be dangerous to call methods
etc on this object. Should only connect to it's signals/slots
	exec();
	//destructor runs when exec() returns... ie when thread is
ending/about-to-end. Since we're still in run(), the destructor runs
on the thread :)
}


...so you could set up an object on it's own thread (incl.
constructor/destructor!) by doing:

LoLCustomThreadImplWithATemplateToo<MyObjectType> threadForMyObject;
connect(&threadForMyObject,
SIGNAL(readyForConnections(MyObjectType*)), this,
SLOT(handleObjectReadyForConnections(MyObjectType*)));
threadForMyObject.start();

void handleObjectReadyForConnections(MyObjectType *obj)
{
	connect(btn, SIGNAL(clicked()), obj, SLOT(doSomethingPleaseAndThankYou()));
	connect(obj, SIGNAL(somethingHappenedDuuuude()), this,
SLOT(handleSomeoneStoleMyCarDude()));
	//etc
}


New Qt class or what?

d3fault



More information about the Interest mailing list