PDA

View Full Version : How to restrict running of more than one instance of application's exe in Qt?



rajeshs
2nd July 2007, 10:05
Hi Friends,

I am using Qt 4.2 in Windows, I am creating one application in Qt, I want to restrict my user to run more than one exe of my application,
Is there any method to do this?

Please Help me.
:)
Thanks,
Rajesh.S

fullmetalcoder
2nd July 2007, 10:15
I you own a Qt commercial license you can have a look at Qt solutions : there's a QtSingleApplication.

However if you want an open-source solution you may be interested in the little class I've crafted : QSingleApplication it uses a temp file and local networking through TCP/IP to check whether an instance is already running and is able to communicate with the existing instance if any :)

jpn
2nd July 2007, 10:16
Limiting the number of instances of one application (http://www.qtcentre.org/forum/f-qt-programming-2/t-limiting-the-number-of-instances-of-one-application-3991.html)
QtSingleApplication (http://trolltech.com/products/qt/addon/solutions/catalog/4/Utilities/qtsingleapplication/)

gri
2nd July 2007, 12:27
With the ActiveQt module you could also use QAxFactory::registerActiveObject()

rajeshs
5th July 2007, 06:16
I you own a Qt commercial license you can have a look at Qt solutions : there's a QtSingleApplication.

However if you want an open-source solution you may be interested in the little class I've crafted : QSingleApplication it uses a temp file and local networking through TCP/IP to check whether an instance is already running and is able to communicate with the existing instance if any :)



Ok please send that singleapplication implementation , i am interested on that ..


Thanks
Rajesh.S

fullmetalcoder
5th July 2007, 20:49
Well I've not packaged anything so you'll have to rely on SVN... Just do a checkout of : https://edyuk.svn.sf.net/svnroot/edyuk/trunk/3rdparty/qcumber All the code resides there (but there are also unrelated classes...) in QSingleApplication, QInterProcessChannel, QManagedSocket and QManagedRequest. The only class you need to know about, for most usess, is QSingleApplication. Just create one instead of a QApplication (or subclass it instead of subclassing directly QApplication) then check isInstanceAllowed() before calling exec() and you're done... :)