Here is the solution I settled for:
The QWS server uses to socket to talk to its clients. I test for the existence of this socket.
I also test whether the server actually has the socked open in order to avoid falling for orphaned sockets left over after a QWS server crash. This is done using lsof
(list open files) on the socket. If the server is running, the list will not be empty and lsof
will return true
. If the server is not running, lsof
will return false
.
On my system the socket was located in /tmp/qtembedded-0/QtEmbedded-0
So here is the bash code:
QWSSOCK=/tmp/qtembedded-0/QtEmbedded-0
if [ ! -S $QWSSOCK ] ; then
echo "No socket $QWSSOCK"
QWSOPT=-qws
elif lsof $QWSSOCK ; then
echo "Server running on $QWSSOCK"
QWSOPT=
else
echo "No server on $QWSSOCK"
QWSOPT=-qws
fi
After this I can run my Qt app using the $QWSOPT
variable:
app $QWSOPT