New Qt user needs help on asynchonous tasks - Xwindows

This is a discussion on New Qt user needs help on asynchonous tasks - Xwindows ; I am in the process of learning to develop simple Linux applications using KDevelop and QT. One application I'm working on requires that I punch a button or enter some text into a text box, and have the contents of ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: New Qt user needs help on asynchonous tasks

  1. New Qt user needs help on asynchonous tasks


    I am in the process of learning to develop simple Linux applications
    using KDevelop and QT.

    One application I'm working on requires that I punch a button or enter
    some text into a text box, and have the contents of the text box sent
    out over a socket to another host. Then the other host replies, and
    the contents of the reply are displayed on another text box.

    I have looked through the QT Designer Manual and the QT Tutorials 1
    and 2, all on the trolltech website, and have figured out how to place
    buttons and text boxes, make the buttons perform the actions I want,
    and send the information out the socket.

    What I haven't figured out is how to asynchronously receive data from
    an outside source and display it.

    It seems that with everything I've seen, one has to take some action
    (push a button, etc.) in order for anything to happen, in that pushing
    a button kicks of a user's subroutine and at all other times the
    program is sitting in some kind of loop or idle task waiting for a
    user event.

    So, how does one make it react to an asynchronous event? How do I
    kick off a routine that, for example, blocks on a socket waiting for
    data to come in, and when the data comes in, displays it in a text
    box?

    (Note: Reading from the socket I can do ... what I need is some help
    on kicking off the routine that does that, and displaying the results
    in a text box, all without having to push a button to make it happen.)

    I spent most of yesterday in Google trying to find information but
    struck out.

    Are there some resources and tutorials on the net that will explain
    this?

    Thanks...

  2. Re: New Qt user needs help on asynchonous tasks

    Eric wrote:
    > I am in the process of learning to develop simple Linux applications
    > using KDevelop and QT.
    >
    > One application I'm working on requires that I punch a button or enter
    > some text into a text box, and have the contents of the text box sent
    > out over a socket to another host. Then the other host replies, and
    > the contents of the reply are displayed on another text box.
    >
    > I have looked through the QT Designer Manual and the QT Tutorials 1
    > and 2, all on the trolltech website, and have figured out how to place
    > buttons and text boxes, make the buttons perform the actions I want,
    > and send the information out the socket.
    >
    > What I haven't figured out is how to asynchronously receive data from
    > an outside source and display it.
    >
    > It seems that with everything I've seen, one has to take some action
    > (push a button, etc.) in order for anything to happen, in that pushing
    > a button kicks of a user's subroutine and at all other times the
    > program is sitting in some kind of loop or idle task waiting for a
    > user event.
    >
    > So, how does one make it react to an asynchronous event? How do I
    > kick off a routine that, for example, blocks on a socket waiting for
    > data to come in, and when the data comes in, displays it in a text
    > box?
    >
    > (Note: Reading from the socket I can do ... what I need is some help
    > on kicking off the routine that does that, and displaying the results
    > in a text box, all without having to push a button to make it happen.)
    >
    > I spent most of yesterday in Google trying to find information but
    > struck out.
    >
    > Are there some resources and tutorials on the net that will explain
    > this?
    >
    > Thanks...


    XtAppAddInput

    --
    Michel Bardiaux
    R&D Director
    T +32 [0] 2 790 29 41
    F +32 [0] 2 790 29 02
    E mailto:mbardiaux@mediaxim.be

    Mediaxim NV/SA
    Vorstlaan 191 Boulevard du Souverain
    Brussel 1160 Bruxelles
    http://www.mediaxim.com/

  3. Re: New Qt user needs help on asynchonous tasks

    Michel Bardiaux wrote:
    > Eric wrote:
    >> I am in the process of learning to develop simple Linux applications
    >> using KDevelop and QT.

    >
    > XtAppAddInput
    >

    That is correct, but it would make the application unportable to
    other platforms (Windows / Mac).
    You should use a Qt function for that purpose.
    Found on http://lists.trolltech.com/qt-interest
    that QSocketNotifier is the equivalent.

    Dušan Peterc
    http://www.arahne.si

  4. Re: New Qt user needs help on asynchonous tasks

    Eric wrote:

    > (Note: Reading from the socket I can do ... what I need is some help
    > on kicking off the routine that does that, and displaying the results
    > in a text box, all without having to push a button to make it happen.)


    connect(theSocket,SIGNAL(readyRead()),this,SLOT(sl otSocketReader()));

    void YourClass::slotSocketReader()
    {
    int nBytesAvailable = theSocket -> bytesAvailable();
    char *caBuffer = new char[nBytesAvailable];

    theSocket -> readBlock(caBuffer,nBytesAvailable);

    .... do stuff with the data ...

    delete [] caBuffer;
    }

    Qt (prior to version 4) uses asynchronous sockets, so you have to do more
    work to make them block than not.


+ Reply to Thread