相关疑难解决方法(0)

即使删除线程,线程数也会增加很多

有一个我有QOBJects的应用程序,它们都包含QNetworkAccessManager.我知道它建议只针对每个应用程序,但由于我在同一时间做了6个以上的调用,我需要像这样.所以,这就是我启动线程的方式.

FileUploader *fileUploader = new FileUploader(_fileList);
QThread *fileUploaderThread = new QThread();
fileUploader->moveToThread(fileUploaderThread);

// uploader > model
connect(fileUploader, SIGNAL(progressChangedAt(int)), _model, SLOT(reportProgressChanged(int)), Qt::QueuedConnection);
connect(fileUploader, SIGNAL(statusChangedAt(int)), _model, SLOT(reportStatusChanged(int)), Qt::QueuedConnection);
// uploader > its thread
connect(fileUploader, SIGNAL(canceled()), fileUploaderThread, SLOT(quit()), Qt::QueuedConnection);
connect(fileUploader, SIGNAL(finished()), fileUploaderThread, SLOT(quit()), Qt::QueuedConnection);
// uploader > this
connect(fileUploader, SIGNAL(canceled()), this, SLOT(deleteFinishedUploader()), Qt::QueuedConnection);
connect(fileUploader, SIGNAL(finished()), this, SLOT(deleteFinishedUploader()), Qt::QueuedConnection);
connect(fileUploader, SIGNAL(finishedCurrentUpload()), this, SLOT(uploadNextFileOrFinish()), Qt::QueuedConnection);
// thread > this
connect(fileUploaderThread, SIGNAL(finished()), this, SLOT(checkIfAllThreadsAreFinished()), Qt::QueuedConnection);
connect(fileUploaderThread, SIGNAL(finished()), this, SLOT(deleteFinishedThread()), Qt::QueuedConnection);
// this > uploader
connect(this, SIGNAL(cancel()), …
Run Code Online (Sandbox Code Playgroud)

c++ qt multithreading qnetworkaccessmanager

13
推荐指数
2
解决办法
1211
查看次数

Qt线程关联性和moveToThread问题

我正在尝试使用Qt中的线程将一些工作委托给一个线程,但是我无法使其工作。我有一个继承QMainWindow的类,该类具有一个启动线程来工作的成员对象。该对象具有QMainwindow作为父对象。它包含并值得注意地初始化了另一个QObject,m_poller我想将其移到我创建的线程中:

m_pollThread = new QThread;
m_poller->moveToThread(m_pollThread);
//Bunch of connection
m_pollThread->start();
Run Code Online (Sandbox Code Playgroud)

我遵循了有关如何在Qt中管理线程而又不对其进行子类化(即不要做错)的准则,但是在VS中我仍然收到以下消息:

QObject :: moveToThread:当前线程(0x2dfa40)不是对象的线程(0x120cf5c0)。无法移动到目标线程(0x1209b520)

我发现以下似乎处理相同问题的帖子,但无法用答案修复我的代码。我觉得我实际上是在正确地调用moveToThread(因为我没有从另一个线程中调用它来“拉”一个对象),但是显然我仍然在那里缺少一些东西:如消息所暗示的那样,似乎已经有多个线程,而我对moveToThread()的调用似乎以错误的方式结束(尽管我承认我对此是全新的,并且可能会发现这是完全错误的...)

那么我使用Qt线程的方式仍然可能出什么问题?

谢谢 !

c++ qt multithreading

5
推荐指数
2
解决办法
9235
查看次数

标签 统计

c++ ×2

multithreading ×2

qt ×2

qnetworkaccessmanager ×1