[Twisted-Python] how to change an qt4 applicaion using twisted?
Hi,all! I have to change an QT application to client-server model, and i found twisted and qt4 reactor. But i don't know where to start? how should i do to split the qt application? what's the step. as for the server, what should i initialize? thanks all.
Hi yangyouxiu, Like Twisted, Qt (and almost all GUI toolkits) work on a single thread, evented mechanism, with an event loop at its core. Qt4Reactor, I believe, just merges these two loops into one loop. The documentation for Qt4Reactor should tell you how to do that. Presumably there's a reactor.install() somewhere :) good luck lvh
Thank you very much. Is it reasonable to bulid only one protocol to deal with datas tranports between client and server ? If in this way, i believe i have to write lots of case to deal with the message, such as to call differnent method,it's impressive. Is there any suggestions? 杨有秀 敬上 From: Laurens Van Houtven Date: 2013-11-17 17:57 To: Twisted general discussion Subject: Re: [Twisted-Python] how to change an qt4 applicaion using twisted? Hi yangyouxiu, Like Twisted, Qt (and almost all GUI toolkits) work on a single thread, evented mechanism, with an event loop at its core. Qt4Reactor, I believe, just merges these two loops into one loop. The documentation for Qt4Reactor should tell you how to do that. Presumably there's a reactor.install() somewhere :) good luck lvh
On Sun, Nov 17, 2013 at 11:10 AM, yangyouxiu
Thank you very much.
Is it reasonable to bulid only one protocol to deal with datas tranports between client and server ? If in this way, i believe i have to write lots of case to deal with the message, such as to call differnent method,it's impressive. Is there any suggestions?
It might be. For simple client<->server interactions using messages, it may be a much better idea to use some existing machinery instead. Many APIs use REST. Twisted provides the tools to do REST, but it also provides other (IMHO better) mechanisms. For example: AMP is a message-based asynchronous protocol. Alternatively, twisted provides PB, which allows you to share objects over the wire. If you like the mental model of a client and a server sending messages to each other, AMP is probably your thing :) cheers lvh
Yangyouxiu, I can definitely help you with this as I've recently written a chat server/client with twisted+PyQt4 and am working on a more complex program that uses PyQt4 with twisted's perspective broker. I have attached five files: 1. client-pyqtreactor.py is a chat client using pyqtreactor and PyQt4. 2. ui.ui is the user interface file loaded by client-pyqtreactor.py 3. server.py is a chat server using asyncore. Note that the server need not use PyQt4 as it has no GUI. 4. constants.py contains configuration data for the client and server 5. qt4reactor.py is the custom reactor Put these all in the same directory, then run the server, then run some clients. When the client window appears click "connect" and then you can use it just like any other network chat program. I hope this helps, and if anyone has suggestions on how to improve the client code please tell me, as I intend on using it as part of a tutorial on twsited+PyQt4. Danie Sank
Thanks for all the suggestions. I will try your advices. 杨有秀 敬上 From: Daniel Sank Date: 2013-11-18 01:01 To: Twisted general discussion Subject: Re: [Twisted-Python] how to change an qt4 applicaion using twisted? Yangyouxiu, I can definitely help you with this as I've recently written a chat server/client with twisted+PyQt4 and am working on a more complex program that uses PyQt4 with twisted's perspective broker. I have attached five files: 1. client-pyqtreactor.py is a chat client using pyqtreactor and PyQt4. 2. ui.ui is the user interface file loaded by client-pyqtreactor.py 3. server.py is a chat server using asyncore. Note that the server need not use PyQt4 as it has no GUI. 4. constants.py contains configuration data for the client and server 5. qt4reactor.py is the custom reactor Put these all in the same directory, then run the server, then run some clients. When the client window appears click "connect" and then you can use it just like any other network chat program. I hope this helps, and if anyone has suggestions on how to improve the client code please tell me, as I intend on using it as part of a tutorial on twsited+PyQt4. Danie Sank _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Daniel Sank
-
Laurens Van Houtven
-
yangyouxiu