Locked interface problem



  • Hello.
    I have a programm with a QGraphicsView which shows a camera image. Sometimes, the interface locks and the image locks too. When I push a button, the image comes back and works again.

    Someone knows which is the problem?

    Thank you very much!!


  • Lifetime Qt Champion

    Hi,

    You are missing information:

    • What version of Qt ?
    • What Platform ?
    • What multimedia backend ?


  • This post is deleted!


  • @SGaist

    I am using Qt 5.7.0 for Windows. I am sending with a signal a cv::mat which I transform to a qpixmap and I show with a QGraphicsView


  • Lifetime Qt Champion

    How are you getting/creating these images ?
    Does that part lock ?



  • @SGaist

    #include "show_processor.h"
    
    CShowProcessor::CShowProcessor(CConfig *pConfig, CBuffMat *pBuffMatProcessed, CListMat *pListMat, QObject *parent) : m_pConfig(pConfig), m_pBuffMatProcessed(pBuffMatProcessed), m_pListMat(pListMat), QObject(parent)
    {
       m_bWorking = false;
       m_bAbort = false;
       m_pPaleta = new PaletaColor;
    }
    
    //###########################################
    // Llamada para empezar el hilo en paralelo #
    //###########################################
    void CShowProcessor::requestWork()
    {
       mutex.lock();
       m_bWorking = true;
       m_bAbort = false;
       mutex.unlock();
       emit workRequested();
    }
    
    //############################################
    // Llamada para terminar el hilo en paralelo #
    //############################################
    void CShowProcessor::abort()
    {
       mutex.lock();
       if (m_bWorking) {
           m_bAbort = true;
       }
       mutex.unlock();
    }
    
    void CShowProcessor::doWork()
    {
       QDateTime dtPreviousSecond = QDateTime::currentDateTime();
       QDateTime dtOperationBefore = dtPreviousSecond;
       QDateTime dtOperationAfter = dtPreviousSecond;
    
       int iSecondFrames = 0;
       int iFPS = 20;
       int iMSecontWait = 0;
       // Pongo float para que sea exacto y no se me cuele ningun frame
       float fMil = 1000;
       float fRodajaTiempo = fMil / iFPS;
       bool bBandera = true;
    
       CDataMat *pDataMatProcessed = NULL;
    
       bool bAbort;
       try {
           while(1)
           {
               mutex.lock();
               bAbort = m_bAbort;
               mutex.unlock();
               if (bAbort)
                   break;
    
               if (bBandera) {
                   bBandera = false;
                   dtPreviousSecond = QDateTime::currentDateTime();
               }
    
               dtOperationBefore = QDateTime::currentDateTime();
    
               //**** INICIO LECTURA MATRIZ PROCESADA ****//
               pDataMatProcessed = m_pBuffMatProcessed->markReadCurrentMat();
    
               if (pDataMatProcessed == NULL) {
                   IFDBG (4) { char sError[100]; std::sprintf(sError, "Thread Show - sin huecos en buffer");  CFileLog::write(sError); }
                   QThread::sleep(1);
                   continue;
               }
    
               //INTRODUCIR LA APLICACION DE LAS PALETAS
               cv::Mat aux;
               aux = m_pPaleta->convertirColor(pDataMatProcessed->getMat());
    
               m_pBuffMatProcessed->unmarkReadMat(pDataMatProcessed);
    
               emit sendDataMat(aux);
    

    Ok, we have to focus in this last part. I take the cv::mat contained in pDataMatProcessed and I send it to MainWindow with this connect:

    connect(m_pShow, SIGNAL(sendDataMat(cv::Mat)), this, SLOT(receiveDataMat(cv::Mat)), Qt::DirectConnection);
    

    Finally, I put this cv::Mat in the QGraphicPixmapItem:

    void MainWindow::receiveDataMat(cv::Mat image) {
        /* MOSTRAR LA IMAGEN EN EL IMAGEVIEW */
        imageViewer->item->setPixmap(QPixmap::fromImage(imageFunc->putImage(image)));
    }
    

  • Moderators

    @ivanicy said in Locked interface problem:

    connect(m_pShow, SIGNAL(sendDataMat(cv::Mat)), this, SLOT(receiveDataMat(cv::Mat)), Qt::DirectConnection);

    You should not use DirectConnection when communicating between threads! Use QueuedConnection.



  • @jsulm Thank you very much!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.