c++ - QThreads vector

标签 c++ qt qthread

<分区>

我正在尝试对我的图像记录应用程序进行多线程处理,以优化性能并防止 GUI 卡住。 我试图创建一个 CaptureThread vector (我的扩展 QThread 的类)但它没有编译...

这是我的代码:

vector<CaptureThread> v_ct_Threads(i_SelectedCameras);

for(int i = 0; i < i_SelectedCameras; i++) {
    v_ct_Threads[i] = CaptureThread(i, qsb_Duration->value());
    v_ct_Threads[i].start();
}

for(int i = 0; i < i_SelectedCameras; i++) {
    v_ct_Threads[i].wait();
}

错误:

use of deleted function ‘CaptureThread& CaptureThread::operator=(CaptureThread&&)’
v_ct_Threads[i] = CaptureThread(i, qsb_Duration->value());

我想这是一个愚蠢的错误,但我是 C++ 和 Qt 的初学者...

最佳答案

删除了CaptureThread的拷贝构造函数,可能是因为QThread无法拷贝。

您可以将 CaptureThreads 的指针放入线程 vector 中。

vector<std::unique_ptr<CaptureThread>> v_ct_Threads(i_SelectedCameras);

for(int i = 0; i < i_SelectedCameras; i++) {
    v_ct_Threads[i] = std::make_unique<CaptureThread>(i, qsb_Duration->value());
    v_ct_Threads[i]->start();
}

for(int i = 0; i < i_SelectedCameras; i++) {
    v_ct_Threads[i]->wait();
}

关于c++ - QThreads vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47797277/

相关文章:

c++ - Valgrind 报告不匹配的 free()/delete/delete []

c++ - 根据模板参数创建字符串

c++ - 使用 Qt 开发音频游戏?

c++ - 如何在 MacOS 运行时更改 Qt 应用程序的停靠栏图标?

c++ - QImage 与 QThreads

c++ - OpenSSL 的 rsautl 无法加载使用 PEM_write_RSAPublicKey 创建的公钥

c++ - 在 openCV 中更改单个像素颜色

qt - Qt Creator "make install"在哪里添加?

python - PyQt中带有QThread的后台线程

c++ - 使用连接的套接字终止 QWebSocketServer