Results 1 to 3 of 3

Thread: Thread eventLoop and run

  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 Thread eventLoop and run

    Hi,

    Can a QThread call "exec()" on "run()" method and then do some work or "exec()" locks?

    I need to call "exec()" because the Thread have a Socket so the events have to be sended to this Thread, but also have to do som work:

    Qt Code:
    1. MyThread::run()
    2. {
    3. if (!m_qSocket.setSocketDescriptor(m_iSocketDescriptor))
    4. {
    5. return;
    6. }
    7. bool bC = connect(&m_qSocket,SIGNAL(readyRead()),this,SLOT(llegirDades()));
    8. bool bC2 = connect(&m_qSocket,SIGNAL(disconnected()),this,SLOT(desconexio()));
    9. exec();
    10. //Here I need to do some work:
    11. ...
    12. //more work, ...
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Thread eventLoop and run


  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Thread eventLoop and run

    Qt Code:
    1. void ZePurpleThread::run()
    2. {
    3. QEventLoop eventLoop;
    4.  
    5. while (mPurpleApi->isLoop())
    6. {
    7. eventLoop.processEvents(QEventLoop::AllEvents);
    8. }
    9.  
    10. // More stuff...
    11. }
    To copy to clipboard, switch view to plain text mode 

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.