[email protected]
[Top] [All Lists]

Re: Creating a QFtp-like class

Subject: Re: Creating a QFtp-like class
From: "Richard Danter"
Date: Wed, 29 Oct 2008 17:44:11 +0000
2008/10/29 Thiago Macieira <[email protected]>:
> Richard Danter wrote:
>>I would like to create a class that processes commands in a sequence
>>asynchronously like QFtp or QHttp. I think I could use a
>>QThread-derived class but neither QFtp nor QHttp seem to be derived
>>this way. What is the correct way to implement a class that does
>>processing this way?
> First of all, I have to warn you that these two classes are not considered
> a very good design. One of the reasons why that is so is because they are
> fragile. It is somewhat related to the way they operate, but mostly
> because they try to expose too much information from the underlying
> protocol.

If you were to re-write them, what would you do differently?

> They are implemented more or less like this:
>  - each public call to functions like setHost, login, get, etc., are
> handled all alike:
>    1) a new "request" is created and added to a queue
>    2) if the queue was empty, it runs:
>        QMetaObject::invokeMethod(this, "handleRequest", Qt::QueuedConnection);
>        (where handleRequest is a slot)
>  - the handleRequest function pops the first request in the queue and
> calls the handler
>  - when the handler is finished, it calls (indirectly) handleRequest again
>  - if the handler is finished by the queue is empty, then it emits the
> done() signal

Given the above comment about fragility, would you do this differently?

My aim is really just to be able to do a load of stuff in the
background without freezing the GUI and without having to force
someone to have to think about threads. There is an article [1] about
making the QSql API async which looks useful. I could maybe roll all
the thread code into my class. Or maybe derive an async class from the
sync one, which seems like a nice idea as console apps could then use
the simpler sync class and not care about signals/slots and even not
have an event (exec) loop.

Just a little more detail about the class. It contains a number of
methods some of which are very quick to execute, like getting error
codes and strings, and others may take some time to complete. Of the
longer (time) methods, some could be broken up but others rely on
functionality from other libs which are beyond my control.

What do you think?


[1] http://www.linuxjournal.com/article/9602

To unsubscribe - send a mail to [email protected] with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>