I have a function that detects camera ports in 3D slicer, however it seems to only run once. When I unplug/plug in a camera, the number of ports should update in a combobox (designed in Qt), but nothing changes.
The function I'm using detects when the camera port is clicked:
void qSlicerTrackingModuleWidget::onCameraPortClicked(){
Q_D(qSlicerTrackingModuleWidget);
// Clear current entries
d->CameraPortComboBox->clear();
int n = 0;
// Loop over camera ports until last one is found. Add all available ports to combo box and exit.
while(1){
cv::VideoCapture cap = cv::VideoCapture(n);
if(!cap.isOpened()){
return;
}
QString portNum = QString::fromStdString(std::to_string(n++));
d->CameraPortComboBox->addItem(portNum);
qSlicerCoreApplication::processEvents();
}
}
The setup function runs last and assigns the GUI to the actual function.
connect( d->CameraPortComboBox, SIGNAL(clicked()), this, SLOT(onCameraPortClicked()));
I need it to refresh and try to detect the cameras every time the combobox is clicked on, but because of the interface setup I am not sure if it is possible. I don't think constantly refreshing the program is a good option, so I'm out of ideas. Is there any way to do this?
Aucun commentaire:
Enregistrer un commentaire