Results 1 to 8 of 8

Thread: Send Qt Signals when a unix domain socket is selectable

  1. #1
    Join Date
    Jan 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Send Qt Signals when a unix domain socket is selectable

    Hello, my question is:
    How to connect Unix domain socket to Qt slot so that when the socket is SELECTABLE a Qt signal is sent?

    I had already have a look to QLocalSocket and QSocketNotifier, but without any success.

    Any hints?

    Thanks.

    Fabi

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Send Qt Signals when a unix domain socket is selectable

    QSocketNotifier is what you want. Look at it again
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Send Qt Signals when a unix domain socket is selectable

    The point is that I wrote the code, I connected the signal QSocketNotifier::activated to my slot but it didn't worked at all..
    I was not able to get those signals

    I read about using unix signals and those are using a trick.. Do I need to use a trick for it too or what?

    Thanks in advance

    Fabi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Send Qt Signals when a unix domain socket is selectable

    Can we see the code you wrote?

    By the way, you can also use QLocalSocket and expect readyRead() to be emitted when data becomes available.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Send Qt Signals when a unix domain socket is selectable

    Finally I found a solution using QLocalSocket and connectToServer.
    I used netstat -na to get the server name in my case /dev/shm/afed.

  6. #6
    Join Date
    Jan 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Send Qt Signals when a unix domain socket is selectable

    unfortunately looks like that it doesn't work as expected

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Send Qt Signals when a unix domain socket is selectable

    What exactly is wrong?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: Send Qt Signals when a unix domain socket is selectable

    Hi,
    This morning I understood what was wrong, basically nothing in the code but just in my mind, I waited for readyRead signals when the reading buffer was already read by a C function in an external lib...
    then everything is fine now.

    Then just for helping other people who are looking for reading unix socket domain with Qt... I write here what I learned..
    (Please comment this if something is wrong)

    First of all, to read Unix domain socket with Qt we have to use QLocalSocket.

    Unix domain socket have a path. You need that path to connect your local socket to the server.
    I got that server path using netstat -na
    In the netstat output, this line has been useful for me:
    unix 2 [ ACC ] STREAM LISTENING 23611 /dev/shm/mydaemon


    Then I wrote this in my QObject derived class:

    Socket = new QLocalSocket(this);
    Socket->connectToServer("/dev/shm/mydaemon", QIODevice::ReadOnly);
    connect(Socket, SIGNAL(readyRead()), this, SLOT(readSocket()));

    In my case I just need to read the output. I don't have to send anything so I used the option QIODevice::ReadOnly.


    The server use send() to send data (in structure :/ ) then this is the code needed to read those data

    void myClass::readSocket(){

    QByteArray ba;
    ba = Socket->readAll();

    if (ba.isEmpty()){
    return;
    }
    qDebug() << "read buffer" << ba.toHex() << ba.size();
    myStruct *resp;
    //Assuming valid this casting in the same machine.
    resp = reinterpret_cast <myStruct*>(ba.data());
    }

    Then thanks for the help and if someone want to comment this code, please do it, in order to leave some info to other people interested in this topic.

    thanks

    fabi

Similar Threads

  1. Replies: 1
    Last Post: 27th March 2009, 13:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.