0

I wrote a simple application to take pictures in c++ and am guessing I probably should do some cleanup whenever CTRL+C is pressed. I am using QTCreator to write the application along with MADDE, but am not really using any Qt hooks that I know of.

How can I handle CTRL+C in my application?

Thanks, Walter

Werner Henze
  • 16,404
  • 12
  • 44
  • 69
Walter
  • 1,290
  • 2
  • 21
  • 46
  • Did you try the `lastWindowClosed()` signal? – J-16 SDiZ Jan 20 '11 at 01:27
  • Uh - I am a Java programmer, I basically modified an application to get to this point. Can you show an example? – Walter Jan 20 '11 at 01:29
  • What sort of cleanup are you thinking of doing? Virtually everything is taken care of by the OS when your process exits. – Greg Hewgill Jan 20 '11 at 01:41
  • Ok, I am using FCam ... according to the documentation, I should do this: sensor.stop(); – Walter Jan 20 '11 at 01:45
  • @Greg I actually a little surprised (not insulted or shocked or anything outrageous like you see on SO too often, just honestly surprised) that someone that I respect as much as you for your technical knowledge asked that. Am I wrong in thinking that it's usually good explicitly call your destructors on cntrl-c? Joining threads, signaling remote systems that you're leaving, all that good stuff? – San Jacinto Jan 20 '11 at 01:48
  • @San Jacinto: When possible, processes should attempt to clean up when they exit gracefully. However, Ctrl+C is what I would call an "ungraceful" exit, where the operator doesn't care whether the process cleans up after itself. In fact, in most cases I would prefer that it wouldn't try to do so, because it might already be hanging for some other reason and I don't want to wait for it to respond to Ctrl+C (after all, if it's hung it might not). In the OP's case, the camera driver is probably a device driver and it will get a notification when a process using it is closed, then it can clean up. – Greg Hewgill Jan 20 '11 at 02:13

1 Answers1

1

It appears that maemo is based on linux. In linux C programs, you get an OS signal that you must write a handler for. You can go that route, but Qt seems to offer a signal that it fires when a program is ready to quit.. http://doc.qt.nokia.com/stable/qcoreapplication.html#aboutToQuit

Here is some more info about how to go about catching the OS signal in question, and then acting on it. Note that if you catch the OS signal, you probably won't get the "aboutToQuit" signal automatically anymore.

http://doc.qt.nokia.com/4.7/unix-signals.html

San Jacinto
  • 8,774
  • 5
  • 43
  • 58
  • I would add that if possible, it's probably better to stick with the "aboutToQuit" signal since it will be cross-platform. – San Jacinto Jan 20 '11 at 01:39