Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why does the slot emit it's connected signal ?
Forum Updated to NodeBB v4.3 + New Features

Why does the slot emit it's connected signal ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 671 Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    Quentin91
    wrote on last edited by
    #1

    *Hi !

    I'm using QOpenGL to print a video on a texture for an QML HMI. I'm using a code that I don't understand and that does not work yet. And i'm completely new to OpenGL

    So today's question is :
    Why would a slot emit the signal that calls this same slot ?

    The signal I'm talking about, void newImageAvailable(); is emitted when a new image is ready to be printed. It's emitted periodically by a QThread. i got this. But the slot is only emitting the signal.
    here are the specific samples of code.

    	void ImageSourceShm::onNewImageAvailable(){
    		// Attention : peut-être exécuté dans le thread du monitor
    		Q_EMIT newImageAvailable();
    	}
    

    i'm trying to understand how the code is supposed to print the image get in the shared memory on a texture...

    JKSHJ 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @Quentin91
      Are you 100% sure that the newImageAvailable signal is connected to onNewImageAvailable?

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      2
      • Q Quentin91

        *Hi !

        I'm using QOpenGL to print a video on a texture for an QML HMI. I'm using a code that I don't understand and that does not work yet. And i'm completely new to OpenGL

        So today's question is :
        Why would a slot emit the signal that calls this same slot ?

        The signal I'm talking about, void newImageAvailable(); is emitted when a new image is ready to be printed. It's emitted periodically by a QThread. i got this. But the slot is only emitting the signal.
        here are the specific samples of code.

        	void ImageSourceShm::onNewImageAvailable(){
        		// Attention : peut-être exécuté dans le thread du monitor
        		Q_EMIT newImageAvailable();
        	}
        

        i'm trying to understand how the code is supposed to print the image get in the shared memory on a texture...

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @quentin91 said in Why does the slot emit it's connected signal ?:

        The signal I'm talking about, void newImageAvailable(); is emitted when a new image is ready to be printed. It's emitted periodically by a QThread.

        Which class contains that signal?

        here are the specific samples of code.

          void ImageSourceShm::onNewImageAvailable(){
          	// Attention : peut-être exécuté dans le thread du monitor
          	Q_EMIT newImageAvailable();
          }
        

        If that signal belongs to ImageSourceShm, then your program will enter an infinite recursion and crash when ImageSourceShm::newImageAvailable() is emitted.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        2
        • Q Offline
          Q Offline
          Quentin91
          wrote on last edited by
          #4

          @fcarney

          @Quentin91
          Are you 100% sure that the newImageAvailable signal is connected to onNewImageAvailable?

          yes, i am

          connect(m_pMonitorThread, SIGNAL(firstImageAvailable(int, int)), this, SLOT(onFirstImageAvailable(int, int)), Qt::DirectConnection);
          connect(m_pMonitorThread, SIGNAL(newImageAvailable()), this, SLOT(onNewImageAvailable()), Qt::DirectConnection);

          If that signal belongs to ImageSourceShm, then your program will enter an infinite recursion and crash when ImageSourceShm::newImageAvailable() is emitted.

          That's weird as this program is the source code of a pyd lib well spread in my companny... The programs using it don't crash.
          Ok, they are sometimes but mostly works.

          Maybe it's because a thread is emitting the signal periodically too ? i still don't get how this program works to print images...

          	void ImageSourceShmMonitorThreadByPeriod::run()
          	{
          		m_pPrecisionTimer->start();//mesure du temps d'attente
          		while (m_pImageSourceShm->isAttached() == false)
          		{
          			QThread::msleep(1);
          		}m_pData = m_pShm->data();
          		QThread::msleep(1);
          		Q_EMIT firstImageAvailable(m_pImageSourceShm->shm()->getWidth(), m_pImageSourceShm->shm()->getHeight());
          
          		m_pPrecisionTimer->start();
          		while (1)
          		{
          			if (m_pPrecisionTimer->elapsed() >= m_dPeriod)
          			{
          				m_pPrecisionTimer->start();
          				Q_EMIT newImageAvailable();//THERE 
          			}
          			QThread::msleep(1);
          		}
          	}
          
          JKSHJ 1 Reply Last reply
          0
          • Q Quentin91

            @fcarney

            @Quentin91
            Are you 100% sure that the newImageAvailable signal is connected to onNewImageAvailable?

            yes, i am

            connect(m_pMonitorThread, SIGNAL(firstImageAvailable(int, int)), this, SLOT(onFirstImageAvailable(int, int)), Qt::DirectConnection);
            connect(m_pMonitorThread, SIGNAL(newImageAvailable()), this, SLOT(onNewImageAvailable()), Qt::DirectConnection);

            If that signal belongs to ImageSourceShm, then your program will enter an infinite recursion and crash when ImageSourceShm::newImageAvailable() is emitted.

            That's weird as this program is the source code of a pyd lib well spread in my companny... The programs using it don't crash.
            Ok, they are sometimes but mostly works.

            Maybe it's because a thread is emitting the signal periodically too ? i still don't get how this program works to print images...

            	void ImageSourceShmMonitorThreadByPeriod::run()
            	{
            		m_pPrecisionTimer->start();//mesure du temps d'attente
            		while (m_pImageSourceShm->isAttached() == false)
            		{
            			QThread::msleep(1);
            		}m_pData = m_pShm->data();
            		QThread::msleep(1);
            		Q_EMIT firstImageAvailable(m_pImageSourceShm->shm()->getWidth(), m_pImageSourceShm->shm()->getHeight());
            
            		m_pPrecisionTimer->start();
            		while (1)
            		{
            			if (m_pPrecisionTimer->elapsed() >= m_dPeriod)
            			{
            				m_pPrecisionTimer->start();
            				Q_EMIT newImageAvailable();//THERE 
            			}
            			QThread::msleep(1);
            		}
            	}
            
            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @quentin91 said in Why does the slot emit it's connected signal ?:

            connect(m_pMonitorThread, SIGNAL(newImageAvailable()), this, SLOT(onNewImageAvailable()), Qt::DirectConnection);

            The sender and receiver are different objects. The sequence is:

            1. The signal, m_pMonitorThread->newImageAvailable(), is emitted
            2. The slot, this->onNewImageAvailable(), is invoked by the previous signal
            3. The signal, this->newImageAvailable(), is emitted in the previous slot
            4. Nothing else happens, because nothing is connected to this->newImageAvailable()

            Notice that #1 and #3 are different signals. I can't figure out what the author is trying to do here, however...

            i'm trying to understand how the code is supposed to print the image get in the shared memory on a texture...

            I don't see any image printing code in your posts.

            P.S. FYI, ImageSourceShm subclassses QThread, implements slots in the subclass, implements an infinite while() loop inside run(), and then forces a Qt::DirectConnection. This is an anti-pattern; please don't do this in new code!

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            Q 1 Reply Last reply
            5
            • JKSHJ JKSH

              @quentin91 said in Why does the slot emit it's connected signal ?:

              connect(m_pMonitorThread, SIGNAL(newImageAvailable()), this, SLOT(onNewImageAvailable()), Qt::DirectConnection);

              The sender and receiver are different objects. The sequence is:

              1. The signal, m_pMonitorThread->newImageAvailable(), is emitted
              2. The slot, this->onNewImageAvailable(), is invoked by the previous signal
              3. The signal, this->newImageAvailable(), is emitted in the previous slot
              4. Nothing else happens, because nothing is connected to this->newImageAvailable()

              Notice that #1 and #3 are different signals. I can't figure out what the author is trying to do here, however...

              i'm trying to understand how the code is supposed to print the image get in the shared memory on a texture...

              I don't see any image printing code in your posts.

              P.S. FYI, ImageSourceShm subclassses QThread, implements slots in the subclass, implements an infinite while() loop inside run(), and then forces a Qt::DirectConnection. This is an anti-pattern; please don't do this in new code!

              Q Offline
              Q Offline
              Quentin91
              wrote on last edited by
              #6

              Thank you very much for this explanation. It's not surprising if I didn't understand then... I'll change this code

              @jksh

              I don't see any image printing code in your posts.

              There aren't any image printing there. For now, a two classes are defined as QQuickItems. One is creating opengl textures, vao and stuff and one other is getting pictures in the sharedMemory. I still don't know how the data are supposed to be sent from the shm classes to the textures classes to be printed but I suppose I'll make another topic about it in a few days...

              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