How can I know - X-server is running or not?

The fact is that I run the application (created with QApplication) and don`t know X-server is running or not. And my application say that "cannot connect to X-server" and crash!

What can I do to work normaly without crash?