[Development] Common base class for all socket types

d3fault d3faultdotxbe at gmail.com
Wed Nov 7 00:47:58 CET 2012


On 11/6/12, Corentin Jabot <corentin.jabot at gmail.com> wrote:
>
> I dont see how the connectTo* methods could be shared, and I don't
> think it would be a good idea to try to do so.
>

I disagree. Having a QList<QAbsrtactSocket*> and then being able to
iterate over them and connectTo* and disconnectFrom* without knowing
their type is helpful. You (_developer_) can't know the duration of
each connection (_user_) either so we could move the traditional
connectTo parameters into a new constructor and expose them as
properties as well. Then QAbstractSocket::connectToHost() would have
no arguments, and we can provide a helper/source-compatible overload
QTcpSocket::connectToHost(host, port) while we're at it. The base type
constructor has no arguments and calling the empty connectToHost
before setting up the properties will just return false.

(I'm conveniently ignoring QObject *parent and Read/ReadWrite args as
they aren't relevant)


Iterating over a list of connections like this is already possible,
but as stated requires glue code and ugly hacky design. This thread is
just about a cleanup. Since no new code is introduced, there's a very
low chance of introducing bugs and it's worth breaking the randomly
declared (in May!) feature freeze.



Additionally, hostName() is shared in the obvious way and we
can/should introduce a url() or some such that would, for example,
append the port after a colon (in relevant subclasses). I guess this
would also imply being able to pass in that url (to yet another
constructor in each subclass) as an alternative to specifying the
host/port as separate args.


d3fault



More information about the Development mailing list