In socket programming, you may want to call select to check which sockets is available. Normally, it is called inside a loop.
But in QT GUI programming, the main loop is encapsulated inside application.exec(). See in below:
int main(argc, argv)
{
QApplication a(argc, argv);
return a.exec();
}
You need to find a way to put your select operation in the loop. How to do?
What I found is,
we may use class QAbstractEventDispatcher to register our own SocketNotifier.
You tell QT framework please pay attention to my SocketNotifier. The SocketNotifier has a parameter of fd, which is your own socket one.
I suspect inside QT framework loop may call select implicitly, which supports the integration of the socket programming.
I haven't checked yet, hope it is a right way to do that. I think It should be the correct direction to integrate the socket programming.
If thinking in a more broad way, we can use this mechanism to integrate any data access operation into QT application. For example, look at the Unix, it use fd to abstract file and socket access. You can also define your data access system with a fd as a key to access.
No comments:
Post a Comment