Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, May 2008
QObject::sender() is NULL


Message 1 in thread

I have my object, created within the main thread which has such a slot:

 

class ClientManager : public QObject

{

      Q_OBJECT

â

public slots:

      void unregisterServer();

 

Also, I have a QTcpSocket, created in another thread.

 

Within one of the methods of ClientManager I connect:

      connect(socket, SIGNAL(disconnected()), this, SLOT(unregisterServer()));

 

void ClientManager::unregisterServer()

{

      QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(sender());

 

And here sender() returns NULL. What can be the cause?

Method unregisterServer() is used only by this connect().

 


Message 2 in thread

Iâve solved the problem myself.

When connecting two objects which belong to different threads, the default connection type is Qt::QueuedConnection. And probably the socket was deleted before the slot was triggered.

The solution is:

       connect(socket, SIGNAL(disconnected()), this, SLOT(unregisterServer()), Qt::BlockingQueuedConnection);

This works well.


Message 3 in thread

Am Donnerstag, 8. Mai 2008 schrieb ÐÐÑÐÐ ÐÐÑÐÑÐÐÐ:
> Iâve solved the problem myself.
> When connecting two objects which belong to different threads, the default
> connection type is Qt::QueuedConnection. And probably the socket was
> deleted before the slot was triggered.
> The solution is:
>        connect(socket, SIGNAL(disconnected()), this,
> SLOT(unregisterServer()), Qt::BlockingQueuedConnection);
> This works well.

But this actually removes all the benefits of using multiple threads. If you 
want blocking behavior, you don't need threads...

Arnold
-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.