QT update video frame cause stuck?
-
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()
}
}@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.
-
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()
}
}@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 anywhile (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.
-
This post is deleted!
-
This post is deleted!
This post is deleted! -
@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 anywhile (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.
@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); } } -
@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); } }@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-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 anywhile (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.
@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. -
@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); } }@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.
-
@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.@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.
-
@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.
@Puppy-Bear said in QT update video frame cause stuck?:
void app0::cropimg() {
qApp->processEvents(QEventLoop::AllEvents, 100);processEvents() is not needed