Connect not working with vector of QThreads
Solved
General and Desktop
-
I cannot connect my QThread's signal to my main thread slot because of a compilation issue. I guess that it is related to the fact that I use a vector of QThreads...
mainwindow.cpp
void MainWindow::startCapture() { ... 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()); QObject::connect(&v_ct_Threads[i], &CaptureThread::signalProgress, this, &MainWindow::updateProgress); // Faulty line v_ct_Threads[i]->start(); } ... } void MainWindow::updateProgress(int i_Camera, int i_Progress) { qpb_Progress[i_Camera]->setValue(i_Progress); }
capturethread.h
... /class CaptureThread : public QThread { Q_OBJECT public: CaptureThread(int i_Camera, int i_Duration); void run(); signals: void signalProgress(int i_Camera, int i_Progress); ... };
error message
.../mainwindow.cpp:156: error: no matching function for call to ‘MainWindow::connect(__gnu_cxx::__alloc_traits<std::allocator<std::unique_ptr<CaptureThread> > >::value_type*, void (CaptureThread::*)(), MainWindow*, void (MainWindow::*)())’ QObject::connect(&v_ct_Threads[i], &CaptureThread::signalProgress, this, &MainWindow::updateProgress); ^
I use QTcreator 4.4.1 Qt 5.9.2, C++14 on Ubuntu 16.