Results 1 to 3 of 3

Thread: Socket on a Thread

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Socket on a Thread

    Hi,

    Can I create a socket on the main thread and move it then to another Thread using "moveToThread"?
    I need the socket to recive the "readyRead" signal into the Thread.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket on a Thread

    Hi,

    My server run method:
    Qt Code:
    1. void Thread::run()
    2. {
    3. if (!m_qSocket.setSocketDescriptor(m_iSocketDescriptor))
    4. {
    5. emit error(m_qSocket.error());
    6. return;
    7. }
    8. bool bC = connect(&m_qSocket,SIGNAL(readyRead()),this,SLOT(readData()));
    9. exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


    If I don't call "exec()" the application crash because can't recive signals...
    The "exec()" method is called to let the Thread recive signals.

    "bC" returns true, but "readData()" is never called.
    The client is sending one single char and then calling flush to ensure that is sended without any wait.


    Thanks,
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket on a Thread

    Hi,

    Sorry, it's working.
    Òscar Llarch i Galán

Similar Threads

  1. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  2. socket in thread error!
    By alphaboy in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2007, 12:15
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. question about socket and threads?
    By oob2 in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2007, 11:42
  5. How to write on a socket in another thread?
    By Valheru in forum Qt Programming
    Replies: 7
    Last Post: 12th October 2006, 10:52

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.