Time delay in loading progress bar (GIF Format)
-
I used to run the progress bar while clicking Read button before the picture scan . But what my result is , it reads the picture and display in screen ,
After that the progress bar runs for a seconds . I think its make no sense .Thanks i Advance
-
@sankarapandiyan said in Something delay in loading progress bar:
Dialog*obj1=new Dialog(this);
// obj1->exec();prog1.setModal(false); prog1.setWindowTitle("Wait"); prog1.exec();*/
Please post code which at least compiles!
Also, the way you're doing it your dialog will not update during the work as you're blocking the event loop. You should more actual work to a thread and emit signal from that thread to update the progress dialog. -
@sankarapandiyan You do all the heavy work inside on_pushButton_4_clicked(). As long as it is not finished your UI will not update, because the event loop is blocked. You should move this heavy work into another thread.
-
@sankarapandiyan There is a dirty workaround: calling https://doc.qt.io/qt-5/qcoreapplication.html#processEvents inside on_pushButton_4_clicked() as often as possible. But it is really this: dirty workaround.
-
@sankarapandiyan
I was going to say same as @jsulm. But in any case, is it safe to useprocessEvents()
inside a slot? Won't that potentially mess things up?I don't know what your code is doing or what " Because i am using GIF Format only" signifies. If you really don't want to do thread, if you do not want to wait till the code is finished inside the pushbutton slot (I don't know if you do), you might be able to use a
QTimer()
to avoid thread....? -
@sankarapandiyan There is an easy way to move some work into another thread: https://doc.qt.io/qt-5/qtconcurrentrun.html
-
@jsulm
I don't want to sully this discussion, but could you just give a quick "yes" or "no" to myBut in any case, is it safe to use
processEvents()
inside a slot? Won't that potentially mess things up?e.g. can't user press button a second time while in slot for first time and cause havoc?
-
@JonB said in Time delay in loading progress bar (GIF Format):
e.g. can't user press button a second time while in slot for first time and cause havoc?
I guess he/she can :-)
But same applies to using thread: you have to make sure you don't trigger the same action when it is already being executed. Not hard to implement (disconnect the slot or use a guard variable). -
@jsulm @JonB I have used process event( ), And i get a output what i want .. But at last both the progress bar gif windows and task windows are closed automatically .Here i want to hide a progress bar gif window at last , but here both windows are closed . So how to fix this problem .
this is my code
void MainWindow::on_pushButton_4_clicked() { QMovie*movie=new QMovie(":/somegif.gif"); qDebug() << "test1"; if(!movie->isValid()){ //something went Wrong return; } //play GIF auto label=new QLabel(); label->resize(400,180); label->setMovie(movie); label->show(); movie->start(); QTimer*timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(PrintDebugInTimer())); timer->start(1000); //start time to close it after 10 sec QTimer::singleShot(10000,[label,&timer]{ // label->close(); label->deleteLater(); timer->stop(); }); Mat image = imread("/home/pi/test.jpg"); //Rect myROI(445, 745, 400, 400); //Mat crop = image(myROI); //imwrite("/home/pi/1.png", crop); Mat roi1 = image( Rect(2000,730,400,400)); Mat roi2 = image( Rect(1220,720,400,400)); Mat roi3 = image( Rect(445,745,400,400)); imwrite("/home/pi/1.png", roi1); imwrite("/home/pi/2.png", roi2); imwrite("/home/pi/3.png", roi3); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(35*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image1 = imread("/home/pi/test.jpg"); Mat roi4 = image1( Rect(2000,730,400,400)); Mat roi5 = image1( Rect(1220,720,400,400)); Mat roi6 = image1( Rect(445,745,400,400)); imwrite("/home/pi/4.png", roi4); imwrite("/home/pi/5.png", roi5); imwrite("/home/pi/6.png", roi6); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(34*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image2 = imread("/home/pi/test.jpg"); Mat roi7 = image2( Rect(2000,730,400,400)); Mat roi8 = image2( Rect(1220,720,400,400)); Mat roi9 = image2( Rect(445,745,400,400)); imwrite("/home/pi/7.png", roi7); imwrite("/home/pi/8.png", roi8); imwrite("/home/pi/9.png", roi9); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(34*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image3 = imread("/home/pi/test.jpg"); Mat roi10 = image3( Rect(2000,730,400,400)); Mat roi11 = image3( Rect(1220,720,400,400)); imwrite("/home/pi/10.png", roi10); imwrite("/home/pi/11.png", roi11); QPixmap pix1,pix2,pix3,pix4,pix5,pix6,pix7,pix8,pix9,pix10,pix11; pix1.load("/home/pi/11.png"); pix2.load("/home/pi/10.png"); pix3.load("/home/pi/9.png"); pix4.load("/home/pi/8.png"); pix5.load("/home/pi/7.png"); pix6.load("/home/pi/6.png"); pix7.load("/home/pi/5.png"); pix8.load("/home/pi/4.png"); pix9.load("/home/pi/3.png"); pix10.load("/home/pi/2.png"); pix11.load("/home/pi/1.png"); pix1 = pix1.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix2 = pix2.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix3 = pix3.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix4 = pix4.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix5 = pix5.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix6 = pix6.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix7 = pix7.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix8 = pix8.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix9 = pix9.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix10 = pix10.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->label_3->setPixmap(pix1); ui->label_4->setPixmap(pix2); ui->label_5->setPixmap(pix3); ui->label_6->setPixmap(pix4); ui->label_7->setPixmap(pix5); ui->label_8->setPixmap(pix6); ui->label_9->setPixmap(pix7); ui->label_10->setPixmap(pix8); ui->label_11->setPixmap(pix9); ui->label_12->setPixmap(pix10); ui->label_13->setPixmap(pix11); Scalar meanValue; meanValue = mean(roi1); qDebug()<<meanValue[0]; qDebug()<<meanValue[1]; qDebug()<<meanValue[2]; }
-
@sankarapandiyan said in Time delay in loading progress bar (GIF Format):
So how to fix this problem
Sorry I don't understand you. What exactly do you want to close and when?
-
@jsulm actually the push button (in the First window )pressed the progress bar runs first , After loading the progress bar window ( second window ). while closing second window simultaneously the first and second windows closed together , But what i want is i need to stay the ( First window ) on rest . i dont want to close ...
-
@sankarapandiyan Sorry, without code I have no idea...
-
@jsulm @JonB @small_bird @mrjj
void MainWindow::on_pushButton_4_clicked() { QMovie*movie=new QMovie(":/somegif.gif"); qDebug() << "test1"; if(!movie->isValid()){ //something went Wrong return; } //play GIF auto label=new QLabel(); label->resize(400,180); label->setMovie(movie); label->show(); movie->start(); QTimer*timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(PrintDebugInTimer())); timer->start(1000); //start time to close it after 10 sec QTimer::singleShot(10000,[label,&timer]{ // label->close(); label->deleteLater(); timer->stop(); }); Mat image = imread("/home/pi/test.jpg"); //Rect myROI(445, 745, 400, 400); //Mat crop = image(myROI); //imwrite("/home/pi/1.png", crop); Mat roi1 = image( Rect(2000,730,400,400)); Mat roi2 = image( Rect(1220,720,400,400)); Mat roi3 = image( Rect(445,745,400,400)); imwrite("/home/pi/1.png", roi1); imwrite("/home/pi/2.png", roi2); imwrite("/home/pi/3.png", roi3); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(35*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image1 = imread("/home/pi/test.jpg"); Mat roi4 = image1( Rect(2000,730,400,400)); Mat roi5 = image1( Rect(1220,720,400,400)); Mat roi6 = image1( Rect(445,745,400,400)); imwrite("/home/pi/4.png", roi4); imwrite("/home/pi/5.png", roi5); imwrite("/home/pi/6.png", roi6); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(34*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image2 = imread("/home/pi/test.jpg"); Mat roi7 = image2( Rect(2000,730,400,400)); Mat roi8 = image2( Rect(1220,720,400,400)); Mat roi9 = image2( Rect(445,745,400,400)); imwrite("/home/pi/7.png", roi7); imwrite("/home/pi/8.png", roi8); imwrite("/home/pi/9.png", roi9); digitalWrite(7,LOW); digitalWrite(5,HIGH); for(int i=0;i<(34*50);i++) { QCoreApplication::processEvents(); digitalWrite(4,1); //delay(0.5);//for milliseconds usleep(250);//for micro seconds digitalWrite(4,0); //delay(0.5);//for milliseconds usleep(250);//for micro seconds } digitalWrite(7,HIGH); popMessageBox(); Mat image3 = imread("/home/pi/test.jpg"); Mat roi10 = image3( Rect(2000,730,400,400)); Mat roi11 = image3( Rect(1220,720,400,400)); imwrite("/home/pi/10.png", roi10); imwrite("/home/pi/11.png", roi11); QPixmap pix1,pix2,pix3,pix4,pix5,pix6,pix7,pix8,pix9,pix10,pix11; pix1.load("/home/pi/11.png"); pix2.load("/home/pi/10.png"); pix3.load("/home/pi/9.png"); pix4.load("/home/pi/8.png"); pix5.load("/home/pi/7.png"); pix6.load("/home/pi/6.png"); pix7.load("/home/pi/5.png"); pix8.load("/home/pi/4.png"); pix9.load("/home/pi/3.png"); pix10.load("/home/pi/2.png"); pix11.load("/home/pi/1.png"); pix1 = pix1.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix2 = pix2.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix3 = pix3.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix4 = pix4.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix5 = pix5.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix6 = pix6.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix7 = pix7.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix8 = pix8.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix9 = pix9.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); pix10 = pix10.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->label_3->setPixmap(pix1); ui->label_4->setPixmap(pix2); ui->label_5->setPixmap(pix3); ui->label_6->setPixmap(pix4); ui->label_7->setPixmap(pix5); ui->label_8->setPixmap(pix6); ui->label_9->setPixmap(pix7); ui->label_10->setPixmap(pix8); ui->label_11->setPixmap(pix9); ui->label_12->setPixmap(pix10); ui->label_13->setPixmap(pix11); Scalar meanValue; meanValue = mean(roi1); qDebug()<<meanValue[0]; qDebug()<<meanValue[1]; qDebug()<<meanValue[2]; }
this is my output
i have checkedwith q debug
https://postimg.cc/gallery/1e0w5cul2/
This is my code and this is my out put
-
@sankarapandiyan Well, your app is actually crashing. The code is pretty messy to be honest.
QTimer*timer=new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(PrintDebugInTimer())); timer->start(1000); //start time to close it after 10 sec QTimer::singleShot(10000,[label,&timer]{ // label->close(); label->deleteLater(); timer->stop(); // It crashes here. Means timer is already destroyed - do you delete it or its parent somewhere? });
-
This post is deleted!
-
@jsulm said in Time delay in loading progress bar (GIF Format):
It crashes here. Means timer is already destroyed
You are Absolutely Right!!!!!!
Now its Works .. Great Thanks ................ @jsulm @mrjj @JonB