Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: QT4 and GLib

  1. #21
    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: QT4 and GLib

    I don't know if you are aware of this, but the thread object and its members live not in the thread executed by its run() method but in the thread that created the QThread subclassed object (hence the socket lives in a different thread than the one operating on it). I don't know if it's important here, but it seems to be that you are not aware of that.

  2. The following user says thank you to wysota for this useful post:

    pdoria (13th March 2008)

  3. #22
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 and GLib

    Quote Originally Posted by jpn View Post
    Well, I'm sorry to say this but you have somewhat severe threading issues there. I strongly recommend reading Multithreading slides from TT DevDays2007 starting from page 33, about thread affinity.
    Thanks for the link. I'll look into it.

    Could you please elaborate on "somewhat severe threading issues there"?
    My noobiness at Qt doesn't allow me to see it at first glance...
    Where do you see them?

    Regards,
    Pedro.

  4. #23
    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: QT4 and GLib

    J-P probably means the same I noticed.

  5. #24
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QT4 and GLib

    Quote Originally Posted by wysota View Post
    I don't know if you are aware of this, but the thread object and its members live not in the thread executed by its run() method but in the thread that created the QThread subclassed object (hence the socket lives in a different thread than the one operating on it). I don't know if it's important here, but it seems to be that you are not aware of that.
    Thanks for the heads-up!

    I must confess that at first reading I almost got baffled with your input!
    Well... what's wrong with using the socket coming from
    Qt Code:
    1. class Server : public QTcpServer
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. unsigned int nbrClients;
    7. Server ( QObject *parent = 0 );
    8.  
    9. protected:
    10. void incomingConnection ( int socketDescriptor );
    11. };
    To copy to clipboard, switch view to plain text mode 
    ?

    and then passing it to
    Qt Code:
    1. myUnit *tunit = new myUnit ( socketDescriptor,this );
    To copy to clipboard, switch view to plain text mode 

    I mean... I have no other discernible way of passing the socket to the thread...

    ADDENDUM:
    I create the socket in
    Qt Code:
    1. class myUnit : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QTcpSocket tcpSocket;
    7. }
    To copy to clipboard, switch view to plain text mode 

    and in
    Qt Code:
    1. myUnit::myUnit ( int socketDescriptor, Server *parent ) : QThread ( parent )
    2. {
    3. // initialize the unit's socket --> provided by Server::incomingConnection()
    4. if ( !tcpSocket.setSocketDescriptor ( socketDescriptor ) )
    5. {
    6. emit error ( tcpSocket.error() );
    7. return;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    I set its descriptor coming from Server::incomingConnection() ...
    What could possibly be wrong with this?

    Thanks,
    Pedro.
    Last edited by pdoria; 13th March 2008 at 14:58.

  6. #25
    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: QT4 and GLib

    You have to create the socket in run() or change its affinity (just remember the thread object can't be its parent then, so you'll have to explicitely call delete on the socket).

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.