I have a C++ application that uses some Qt libraries. The application works fine until the screen saver pops up and starts. After that if I quit from screen saver the application crashes and I have to re-start it again. I have tested the application on Windows 7 and XP and this happens on both.
Is there anything I can change in the code so this does not happen?
Luca Carlon give you good and fairly popular advice -- use debugger. In your case, you can get a lot of information about debugging from official documentation.
When you run debug of your program, you must replay situation when your program falls: you must manually start screensaver, or hurry up screensaver to start.
When your program fails -- get back-trace, and try to understand, what was wrong.