mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 13:07:04 +02:00
PR comments
This commit is contained in:
parent
86e3489167
commit
0e508432c4
1 changed files with 8 additions and 3 deletions
|
@ -38,11 +38,14 @@ void setThreadName(const std::string& name) {
|
||||||
|
|
||||||
void moveToNewNamedThread(QObject* object, const QString& name, std::function<void(QThread*)> preStartCallback, std::function<void()> startCallback, QThread::Priority priority) {
|
void moveToNewNamedThread(QObject* object, const QString& name, std::function<void(QThread*)> preStartCallback, std::function<void()> startCallback, QThread::Priority priority) {
|
||||||
Q_ASSERT(QThread::currentThread() == object->thread());
|
Q_ASSERT(QThread::currentThread() == object->thread());
|
||||||
// setup a thread for the NodeList and its PacketReceiver
|
|
||||||
|
// Create the target thread
|
||||||
QThread* thread = new QThread();
|
QThread* thread = new QThread();
|
||||||
thread->setObjectName(name);
|
thread->setObjectName(name);
|
||||||
|
|
||||||
// Execute any additional work to do before the thread starts (like moving members to the target thread
|
// Execute any additional work to do before the thread starts like moving members to the target thread.
|
||||||
|
// This is required as QObject::moveToThread isn't virutal, so we can't override it on objects that contain
|
||||||
|
// an OpenGLContext and ensure that the context moves to the target thread as well.
|
||||||
preStartCallback(thread);
|
preStartCallback(thread);
|
||||||
|
|
||||||
// Link the in-thread initialization code
|
// Link the in-thread initialization code
|
||||||
|
@ -54,8 +57,10 @@ void moveToNewNamedThread(QObject* object, const QString& name, std::function<vo
|
||||||
startCallback();
|
startCallback();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure the thread will be destroyed and cleaned up
|
// Make sure the thread will be destroyed and cleaned up. The assumption here is that the incoming object
|
||||||
|
// will be destroyed and the thread will quit when that occurs.
|
||||||
QObject::connect(object, &QObject::destroyed, thread, &QThread::quit);
|
QObject::connect(object, &QObject::destroyed, thread, &QThread::quit);
|
||||||
|
// When the thread itself stops running, it should also be deleted.
|
||||||
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||||
|
|
||||||
// put the object on the thread
|
// put the object on the thread
|
||||||
|
|
Loading…
Reference in a new issue