If the you are doing this because you want a Qt application to prohibit multiple copies of itself then QtSingleApplication can do that for Qt applications.
If you want a general, nothing-to-do-with-Qt, approach for X11 systems then I suggest you look at the source of xwininfo to get an idea how to traverse the window information. The "-all" option shows the PID probably using the approach here: http://unix.stackexchange.com/questi...his-x11-window
The same information is visible using xprop.
Bookmarks