mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #380, QConcurrent vs QThread sample and fix
* in same step fixed nullptr issue in worker (with no parent) * Changed from QConccurennt::run to CWorker in core
This commit is contained in:
@@ -46,8 +46,11 @@ namespace BlackMisc
|
||||
|
||||
auto *thread = new CRegularThread(m_owner);
|
||||
|
||||
QString ownerName = m_owner->objectName().isEmpty() ? m_owner->metaObject()->className() : m_owner->objectName();
|
||||
thread->setObjectName(ownerName + ":" + m_name);
|
||||
if (m_owner)
|
||||
{
|
||||
QString ownerName = m_owner->objectName().isEmpty() ? m_owner->metaObject()->className() : m_owner->objectName();
|
||||
thread->setObjectName(ownerName + ":" + m_name);
|
||||
}
|
||||
setObjectName(m_name);
|
||||
|
||||
moveToThread(thread);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace BlackMisc
|
||||
void ps_finish();
|
||||
|
||||
private:
|
||||
QObject *m_owner;
|
||||
QObject *m_owner = nullptr;
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "blackcore/context_application.h"
|
||||
#include "blackcore/context_application_impl.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/networkutils.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/project.h"
|
||||
@@ -81,8 +82,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
// tool to allow input indepent from event loop
|
||||
cout << "Will start server loop ... " << endl;
|
||||
QFuture<void> future = QtConcurrent::run(BlackMiscTest::Tool::serverLoop, coreRuntime);
|
||||
Q_UNUSED(future);
|
||||
BlackMisc::CWorker *worker = BlackMisc::CWorker::fromTask(coreRuntime, "BlackMiscTest::Tool::serverLoop", [coreRuntime]()
|
||||
{
|
||||
BlackMiscTest::Tool::serverLoop(coreRuntime);
|
||||
});
|
||||
|
||||
Q_UNUSED(worker);
|
||||
cout << "Server event loop, pid: " << BlackMiscTest::Tool::getPid() << " Thread id: " << QThread::currentThreadId() << endl;
|
||||
|
||||
// end
|
||||
|
||||
Reference in New Issue
Block a user