[Qt-interest] QTcpSocket timeouts
Anatoly Burakov
burakov.anatoly at googlemail.com
Thu Mar 18 04:03:36 CET 2010
> Yes. Following Qt's programming model would probably help a lot.
>
> That means you need something event-driven, so the event loop runs and
> you respond to events it generates. Just as a rough example, you need
> to have a class (say, "SocketEvent") that has slots that can receive
> signals generated by your sockets. Hook things up, and then run the
> event loop.
>
> For example, if you are writing a console app, you could do something
> like this (minimal and untested):
>
> int main(int argc, char* argv[])
> {
> ...
> QCoreApplication app(argc, argv);
>
> // set up sockets
> QTcpSocket* my_socket = new QTcpSocket();
> <further setup here>
>
> // create my signal-processing class instance
> SocketEvent* my_socket_event = new SocketEvent(my_socket);
>
> // connect signals to slots
> QObject::connect(my_socket_event, SIGNAL(readyRead()),
> my_socket_event, SLOT(read_device()));
> <further setup here>
>
> // run the Qt event loop
> int result = app.exec();
>
> // clean up
> QObject::disconnect(my_socket_event, SIGNAL(readyRead()),
> my_socket_event, SLOT(read_ready()));
> <further cleanup here>
>
> delete my_socket_event;
>
> // exit
> return result;
> }
>
> Qt will then perform the data processing and queuing for you within the
> event loop, and your processing class ("SocketEvent") will receive
> notification that data is ready without having to block and busy wait
> things.
>
I knew i was missing something :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5238 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100318/eed54ca2/attachment.bin
More information about the Qt-interest-old
mailing list