Question

It's a general question about qthreads, I know how to use the movethread() function but that was for object that was not created dynamically.

The user will create the object on a GUI application by selecting add button. A remove button will also be available if the user would like to remove that object that was created. The user should be able to select the object from the listview. I've already created examples of a custom listview using qstyleditemdelegate, I know how to move the list into a model. I'm worried about the threads.

What I would like to do is allow the user to create an object of a certain class dynamically. Each object with then be moved into qthread. Should I keep looking? Any tips, tricks or hints?

Can I create a function that moves the object into a thread?

Pseudo Code: 
void MoveThisObject(MyCustomObject Object)
{
       QThread* thread = new QThread;
       Object->moveToThread(thread);
       /****setup connections****/

       thread->start();
}

I'm still writing down what I'll need, I haven't really created the actual application.

Was it helpful?

Solution

You can move a QObject (as long as it's not a QWidget, of course) to a different thread regardless of whether it was created dynamically or not. Most QObjects in most applications are created dynamically anyway, or else it would be difficult for them to be polymorphic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top