C++ multithreading: QSocketNotifier:Socket notifiers cannot be enabled or disabled from another thread -


i have 3 threads. main thread (for gui) -> worker thread -> worker thread b

in worker thread b (in code called recognitionthread) trying start process , write data process. process supposed start python virtual environment (this part works) , execute commands in environment (that doesn t work).

when try write data process get: socket notifiers cannot enabled or disabled thread

i think kind of understand problem is, not totally , have no clue how solve issue.

those relevant parts of code:

  • recognitionclass.cpp:

      qprocess recognitionclass::p;   recognitionclass::recognitionclass(qobject *parent) : qobject(parent) {      startpythonvirtualenv(); }  void recognitionclass::startpythonvirtualenv() {     qregistermetatype<qprocess::processerror>("qprocess::processerror"); params<<"-f"<<"-c"<<"python2"<< "/home/john/desktop/python.log";     qdebug()<<"parameters: "<<params;      if(p.state()==2)     {qdebug()<<"python virtualenv running";}     else     {         p.start("script", params);         qdebug()<<"started process";         while(!p.waitforstarted())         {qdebug()<<"waiting virtualenv ready";}     }  }  recognitionclass::person recognitionclass::runrecognitionscript() {       person persstrobj;        qregistermetatype<qprocess::processerror>("qprocess::processerror");       connect(&p, &qprocess::erroroccurred, qapp, &qapplication::aboutqt );         qint64 successfailwrite;        delay();        qdebug()<<"before p.write()";        successfailwrite = p.write("import imp; foo = imp.load_source('mytest', '/home/john/openface/demos/recognitionclass.py'); mytest import recognitionclass; myclassobj = recognitionclass(); print myclassobj.recognize('/home/john/desktop/camera.jpg');");        qdebug()<<"after p.write()";        delay();         qdebug()<<"started process, result write op: "<< successfailwrite;  } 
  • recognitionclass.h:

         class recognitionclass : public qobject      {          q_object      private:          struct person{              qstring persname;              double perscertitude;          };           static qprocess p;          qstringlist params;       public:          explicit recognitionclass(qobject *parent = nullptr);          struct person runrecognitionscript();          void startpythonvirtualenv();          void stoppythonvirtualenv();          void delay();      signals:       public slots:          double recognizeperson();      }; 
  • webcamclass.cpp:

         webcamclass::webcamclass(qobject *parent) : qobject(parent)      {          recognizeperson=false;           //setup recognition thread          recognitionthread = new qthread(this);          recognitionclobj = new recognitionclass();           connect( recognitionthread, signal(started()), recognitionclobj, slot(recognizeperson()) );          recognitionclobj->movetothread(recognitionthread);      }        void webcamclass:: getvideoframe()      {          static cv::videocapture cap(cv_cap_any);          cv::mat imgframe;           if( !cap.isopened() )          {              qdebug()<< "could not initialize capturing...\n";          }           while(1)          {              cap >> imgframe;              cv::cvtcolor(imgframe, imgframe, cv_bgr2rgb);              qimage img;              img = qimage((uchar*)imgframe.data, imgframe.cols, imgframe.rows, qimage::format_rgb888);              qpixmap pixmap = qpixmap::fromimage(img);               emit gottenvideoframe(pixmap);              if(recognizeperson==true)              {                  //write image recognition buffer                  recognitionthread->start();                   if(myglobalvariable==0)                  {                       frameforrecognition = imgframe;                       myglobalvariable=55;                  }               }               cv::waitkey(100);          }      } 

webcamclass (aka worker thread a) worker thread creates new worker thread implementing recognitionclass. (recognitionthread, aka worker thread b) inside recognitionthread try create process start python virtual environment in constructor. works. error occurs @ runtime @ line containing successfailwrite = p.write("import imp...."); in recognitionclass.cpp file on line 37.

my guess tryong program in bad way why bumping 1 problem another. read other posts related similar issues, unable find way out.

could please provide explanation please?

thanks!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -