1
Hello, I’m doing a C++ project using QT GUI. In the project in question I need to display images of a camera in the window, but in doing so, the performance of the window is very compromised, all other buttons and features that includes in the window are slow, overloaded apparently. Below is the capture code of the device images.
void mainwindow::on_ButtonShowCamera_clicked(){
ligaCam = true;
if(!this->cap.isOpened()){ // se ja estiver aberto, nao abre denovo //
this->cap.open(0);
}
QImage img;
while(ligaCam == true){
Mat frame;
this->cap.read(frame);
img = MatToQImage(frame); // converte tipo Mat para QImage //
ui->labelScreen->setPixmap(QPixmap::fromImage(img));
ui->labelScreen->setScaledContents(true);
qApp->processEvents();
//imshow("help", frame);
if (waitKey(30) >= 0)
break;
}
}
The link variable is in charge of changing the value when I click another button (Close Camera) to exit the loop.
My question is, is there any way to display camera images on Qlabel using another thread? Or if there is any way to display the images without overloading the window in question? Thanks for your help.
Thanks for the reply, I followed your advice above but now I came across the following error message: 'SIGNAL was not declared in this Scope'. And the second message is 'macro Signal passed 3 Arguments but takes just 1' . I even installed the Qtimer libraries, although I didn’t need to, but the error persists. I would know what this problem could be?
– Yuri Pires
Probably something wrong with your method statement
onTimeout
(he was declared a slot, in a class inherited fromQObject
and that uses the macroQ_OBJECT
- as indicated Qt documentation for the inter-object communication mechanism?). Anyway, since it’s another problem you should open another question. :)– Luiz Vieira
Ah, and if that answer helped you, please consider marking it as accepted.
– Luiz Vieira
I got it! actually it was all right with the macro and the class, the error was in the connect() statement, I think q lost some parentheses of the function, and my compiler did not accuse rs, Well, Thanks for the answer, solved my problem friend, Hug!
– Yuri Pires
Reply accepted, thank you again.
– Yuri Pires