Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect not working with vector of QThreads
QtWS25 Last Chance

Connect not working with vector of QThreads

Scheduled Pinned Locked Moved Solved General and Desktop
qthread
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bs55
    wrote on last edited by bs55
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Change &v_ct_Threads[i] to v_ct_Threads[i].get()

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 1 Reply Last reply
      4
      • B Offline
        B Offline
        bs55
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • VRoninV VRonin

          Change &v_ct_Threads[i] to v_ct_Threads[i].get()

          B Offline
          B Offline
          bs55
          wrote on last edited by
          #4

          @VRonin Merci :-)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved