PDA

View Full Version : Crashes when activated



bnilsson
29th August 2009, 14:34
I have a project where I am communicating with a USB camera.
I have a slider that controls stuff related to the camera which needs careful checking of the status before sending the control actions to it.
I got this to work reasonably well, except in one situation:
When the window is out of focus (e.g. when MacOSX Finder is active and the app window is grey in the background) and I click on the slider to activate the window, the app crashes, the USB is stalling.
If I click somewhere else on the window to get it in focus (or is it called "activated"?) and THEN touch the slider, it works.

How can I catch his focus/activate event?
I probably need to disable slider action in this case?

vfernandez
29th August 2009, 14:56
Do you have any slot connected to that slider? Where did you define the slider? Could you post some relevant code? A backtrace would also be helpful.

bnilsson
29th August 2009, 15:18
The slots are like this:


connect(ZoomSlider, SIGNAL(sliderPressed()), this, SLOT(DoAbort()));
connect(ZoomSlider, SIGNAL(sliderReleased()), this, SLOT(Restart()));

The camera is doing live imaging, and pressing the slider aborts this.
The camera should not be active when the slider is moved.
The camera should restart the live imaging with new parameters when the slider is released at its new position.

The Stop:

void
CameraWindow::DoAbort() {
int rc=0;
if(busy) return;
printf("\nAborting...");
aborting = true;
if(LiveThread->isRunning()) {
busy = true;
rc = AbortCameraLive(); // camera SDK call
LiveThread->wait();
// The camera thread will emit busy=false when finished and ready to reset.
while(busy) QApplication::processEvents();
}
CameraExit(); // camera SDK call
inited = false;
CameraInit(); // camera SDK call
aborting = false;


And the Restart:

void
CameraWindow::Restart()
{
if(busy) return;
if(aborting) return;

zoomcontrol = ZoomSlider->value();

DelayedLiveDisplay.start(500); // safer
}


There are surely many ways to do this, but now I am concentrating to get this scheme robust so that sloppy clicking around will not stall the camera.

bnilsson
29th August 2009, 15:50
I don't know if this is the final solution, but it certainly helped:


void
CameraWindow::DoAbort() {
int rc=0;
QApplication::processEvents(); // << new addition
if(busy) return;
printf("\nAborting...");
aborting = true;
if(LiveThread->isRunning()) {
busy = true;
rc = AbortCameraLive(); // camera SDK call
LiveThread->wait();
// The camera thread will emit busy=false when finished and ready to reset.
while(busy) QApplication::processEvents();
}
CameraExit(); // camera SDK call
inited = false;
CameraInit(); // camera SDK call
aborting = false;
}

It got much less prone to crash in this situation, and if it still does, it is not crashing in the same way as before:)