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. QT update video frame cause stuck?
Forum Updated to NodeBB v4.3 + New Features

QT update video frame cause stuck?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 1.1k 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.
  • Puppy BearP Puppy Bear

    HI, I have notice the problem before, but while I tried to set the slot like while(1){crop the image} and emit the signal only once, this would still cause a stuck, I'm confused that the slot won't take much time to crop the image, is it a must to use another thread? Or maybe should I try QTimer?

    Okay I've just found out that i'm missing the processEvents, it should be able to realize to re-activate the slot like this, thanks for advice!
    slot{
    while(1)
    {
    qApp->processEvents();
    msleep()
    }
    }

    eyllanescE Offline
    eyllanescE Offline
    eyllanesc
    wrote on last edited by
    #4

    @Puppy-Bear Using processEvent and sleep is unnecessary. Send the signal only once and you should not have problems, if the slot associated with the signal is not called then there is something wrong with your program.

    If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

    1 Reply Last reply
    2
    • Puppy BearP Puppy Bear

      HI, I have notice the problem before, but while I tried to set the slot like while(1){crop the image} and emit the signal only once, this would still cause a stuck, I'm confused that the slot won't take much time to crop the image, is it a must to use another thread? Or maybe should I try QTimer?

      Okay I've just found out that i'm missing the processEvents, it should be able to realize to re-activate the slot like this, thanks for advice!
      slot{
      while(1)
      {
      qApp->processEvents();
      msleep()
      }
      }

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #5

      @Puppy-Bear said in QT update video frame cause stuck?:

      slot{
      while(1)
      {
      qApp->processEvents();
      msleep()
      }
      }

      Even if using processEvents()/msleep() were the right thing to do --- which is not the case --- you should realise that any while (1) would mean the slot never exits. Which would be disastrous, and you should understand why.

      As @eyllanesc have said, just one plain send of signal. Anything then wrong is another matter.

      Puppy BearP JonBJ 2 Replies Last reply
      1
      • Puppy BearP Offline
        Puppy BearP Offline
        Puppy Bear
        wrote on last edited by Puppy Bear
        #6
        This post is deleted!
        Puppy BearP 1 Reply Last reply
        0
        • Puppy BearP Puppy Bear

          This post is deleted!

          Puppy BearP Offline
          Puppy BearP Offline
          Puppy Bear
          wrote on last edited by
          #7
          This post is deleted!
          1 Reply Last reply
          0
          • JonBJ JonB

            @Puppy-Bear said in QT update video frame cause stuck?:

            slot{
            while(1)
            {
            qApp->processEvents();
            msleep()
            }
            }

            Even if using processEvents()/msleep() were the right thing to do --- which is not the case --- you should realise that any while (1) would mean the slot never exits. Which would be disastrous, and you should understand why.

            As @eyllanesc have said, just one plain send of signal. Anything then wrong is another matter.

            Puppy BearP Offline
            Puppy BearP Offline
            Puppy Bear
            wrote on last edited by
            #8

            @JonB Hi I'm actually trying to crop image from camera capture thread, so it would be a infinite loop, and keep sending it to a preprocess thread.
            my code looks like this and it seems running normal right now,
            If it's not a nice way to run with, would you please show me how am I able to execute a loop inside a thread's slot?
            My code is below:
            promoted QLabel:

            void MyLabel::mouseReleaseEvent(QMouseEvent *e){
            if(mouse_released==true){
            emit updaterate(m_roi, this->width(), this->height());
            }
            

            SLOT in mainwindow.cpp

            void app0::updateroi(QRectF roi, double label_w, double label_h)
            {
            	thread2.start();//sending cropped img to this thread, using movetoThread
            	while(1){
            		qApp->processEvents();
            		crop_image_function();
            		if(image.isNull()==false){
            			emit sendcropimage(image); //I'm connecting it with my preprocess thread's slot
            			cout << "send crop image" << "\n";
            			ui->videoviewer2->setPixmap(QPixmap::fromImage(image));//crop from member QImage and showing it
            			}
            		QThread::msleep(30);
            	}
            }
            
            jsulmJ J.HilkJ 2 Replies Last reply
            0
            • Puppy BearP Puppy Bear

              @JonB Hi I'm actually trying to crop image from camera capture thread, so it would be a infinite loop, and keep sending it to a preprocess thread.
              my code looks like this and it seems running normal right now,
              If it's not a nice way to run with, would you please show me how am I able to execute a loop inside a thread's slot?
              My code is below:
              promoted QLabel:

              void MyLabel::mouseReleaseEvent(QMouseEvent *e){
              if(mouse_released==true){
              emit updaterate(m_roi, this->width(), this->height());
              }
              

              SLOT in mainwindow.cpp

              void app0::updateroi(QRectF roi, double label_w, double label_h)
              {
              	thread2.start();//sending cropped img to this thread, using movetoThread
              	while(1){
              		qApp->processEvents();
              		crop_image_function();
              		if(image.isNull()==false){
              			emit sendcropimage(image); //I'm connecting it with my preprocess thread's slot
              			cout << "send crop image" << "\n";
              			ui->videoviewer2->setPixmap(QPixmap::fromImage(image));//crop from member QImage and showing it
              			}
              		QThread::msleep(30);
              	}
              }
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Puppy-Bear said in QT update video frame cause stuck?:

              void app0::updateroi(QRectF roi, double label_w, double label_h)
              {
              thread2.start();//sending cropped img to this thread, using movetoThread
              while(1){

              Do you understand that updateroi(...) will hang forever because you have an infinite loop inside without any break condition?
              Use a QTimer to trigger actions on a regular basis instead of doing strange hacks.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Puppy BearP 1 Reply Last reply
              2
              • JonBJ JonB

                @Puppy-Bear said in QT update video frame cause stuck?:

                slot{
                while(1)
                {
                qApp->processEvents();
                msleep()
                }
                }

                Even if using processEvents()/msleep() were the right thing to do --- which is not the case --- you should realise that any while (1) would mean the slot never exits. Which would be disastrous, and you should understand why.

                As @eyllanesc have said, just one plain send of signal. Anything then wrong is another matter.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #10

                @Puppy-Bear

                @JonB said in QT update video frame cause stuck?:

                you should realise that any while (1) would mean the slot never exits. Which would be disastrous, and you should understand why.

                1 Reply Last reply
                0
                • Puppy BearP Puppy Bear

                  @JonB Hi I'm actually trying to crop image from camera capture thread, so it would be a infinite loop, and keep sending it to a preprocess thread.
                  my code looks like this and it seems running normal right now,
                  If it's not a nice way to run with, would you please show me how am I able to execute a loop inside a thread's slot?
                  My code is below:
                  promoted QLabel:

                  void MyLabel::mouseReleaseEvent(QMouseEvent *e){
                  if(mouse_released==true){
                  emit updaterate(m_roi, this->width(), this->height());
                  }
                  

                  SLOT in mainwindow.cpp

                  void app0::updateroi(QRectF roi, double label_w, double label_h)
                  {
                  	thread2.start();//sending cropped img to this thread, using movetoThread
                  	while(1){
                  		qApp->processEvents();
                  		crop_image_function();
                  		if(image.isNull()==false){
                  			emit sendcropimage(image); //I'm connecting it with my preprocess thread's slot
                  			cout << "send crop image" << "\n";
                  			ui->videoviewer2->setPixmap(QPixmap::fromImage(image));//crop from member QImage and showing it
                  			}
                  		QThread::msleep(30);
                  	}
                  }
                  
                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #11

                  @Puppy-Bear said in QT update video frame cause stuck?:

                  thread2.start();//sending cropped img to this thread, using movetoThread

                  I kind of doubt you're doing any "threading" at all.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Puppy-Bear said in QT update video frame cause stuck?:

                    void app0::updateroi(QRectF roi, double label_w, double label_h)
                    {
                    thread2.start();//sending cropped img to this thread, using movetoThread
                    while(1){

                    Do you understand that updateroi(...) will hang forever because you have an infinite loop inside without any break condition?
                    Use a QTimer to trigger actions on a regular basis instead of doing strange hacks.

                    Puppy BearP Offline
                    Puppy BearP Offline
                    Puppy Bear
                    wrote on last edited by
                    #12

                    @JonB Hi Thanks for your reminding, as my limit of experience, I have updated my code below.

                    timer = new QTimer(this);
                    timer->setInterval(20);
                    timer->start(); 
                    
                    void app0::updateroi(QRectF roi, double label_w, double label_h)
                    {
                    	timer->setInterval(20);
                    	timer->start();}
                    void app0::stop_timer() {
                    	timer->stop();
                    }
                    void app0::cropimg() {
                    	qApp->processEvents(QEventLoop::AllEvents, 100);
                    	//Do some crop img preprocess here
                    }
                    

                    @eyllanesc said in QT update video frame cause stuck?:

                    @Puppy-Bear Using processEvent and sleep is unnecessary. Send the signal only once and you should not have problems, if the slot associated with the signal is not called then there is something wrong with your program.

                    It's been mentioned that processEvent is unecessary which made me a little confused earlier.

                    jsulmJ 1 Reply Last reply
                    0
                    • Puppy BearP Puppy Bear

                      @JonB Hi Thanks for your reminding, as my limit of experience, I have updated my code below.

                      timer = new QTimer(this);
                      timer->setInterval(20);
                      timer->start(); 
                      
                      void app0::updateroi(QRectF roi, double label_w, double label_h)
                      {
                      	timer->setInterval(20);
                      	timer->start();}
                      void app0::stop_timer() {
                      	timer->stop();
                      }
                      void app0::cropimg() {
                      	qApp->processEvents(QEventLoop::AllEvents, 100);
                      	//Do some crop img preprocess here
                      }
                      

                      @eyllanesc said in QT update video frame cause stuck?:

                      @Puppy-Bear Using processEvent and sleep is unnecessary. Send the signal only once and you should not have problems, if the slot associated with the signal is not called then there is something wrong with your program.

                      It's been mentioned that processEvent is unecessary which made me a little confused earlier.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @Puppy-Bear said in QT update video frame cause stuck?:

                      void app0::cropimg() {
                      qApp->processEvents(QEventLoop::AllEvents, 100);

                      processEvents() is not needed

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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