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

Qt-interest Archive, February 2008
Cannot queue arguments / qRegisterMetaType


Message 1 in thread

Hi all!

I try to write a DLL for tcp-communication with a server. The DLL contains a 
subclass of QThread. Inside the run-method I create a QTcpSocket
and establish connections to several methods. When the signals
> stateChanged( QAbstractSocket::SocketState ) or error( 
> QAbstractSocket::SocketError )
are invoked I get error messages like:

QObject::connect: Cannot queue arguments of type 
'QAbstractSocket::SocketError'
(Make sure 'QAbstractSocket::SocketError' is registered using 
qRegisterMetaType().)

I tried a lot with qRegisterMetaType() and Q_DECLARE_METATYPE but I cant get 
this working.

Thanks in advance for your help!
thil


// here the simplified code:
// MainProc.exe

int main(int argc, char *argv[] )
{
   QApplication qapplication( argc, argv );
   QWidget mainWidget;

   CommThread* commThread = new SWCPCommThread(  NULL, "192.168.178.22" );

   QPushButton startButton( QString( "start Thread" ), &mainWidget );
   QObject::connect( &startButton, SIGNAL( clicked() ), commThread, SLOT( 
start() ) );

   mainWidget.setWindowTitle( QString( "Hello World" ) );
   mainWidget.show();
   return qApp->exec();
}


//from communication.dll

void CommThread::run()      // implements QThread::run()
{

 int qtype1 = 
qRegisterMetaType<QAbstractSocket::SocketError>("SocketError" );  // Result 
is 256
 int qtype2 = 
qRegisterMetaType<QAbstractSocket::SocketState>("SocketState" );  // Result 
is 257

 m_Socket = new QTcpSocket();
 bool b1 = connect( m_Socket, SIGNAL( error( 
QAbstractSocket::SocketError ) ), this, SLOT( onError( 
QAbstractSocket::SocketError ) ) );
 bool b2 = connect( m_Socket, SIGNAL( stateChanged( 
QAbstractSocket::SocketState ) ), this, SLOT( onStateChanged( 
QAbstractSocket::SocketState ) ) );

 Q_ASSERT( b1 );
 Q_ASSERT( b2 );  //everthing is fine!

  m_Socket->connectToHost( m_Servername, m_Port );
 exec();
}


--
 [ signature omitted ] 

Message 2 in thread

thil wrote:
>qRegisterMetaType<QAbstractSocket::SocketError>("SocketError" );  //
> Result is 256
> int qtype2 =
>qRegisterMetaType<QAbstractSocket::SocketState>("SocketState" );  //
> Result is 257

Add the QAbstractSocket:: prefix.

But, better yet, use direct connections. You don't want a queued 
connection.

Or, more simply yet, don't use your QThread-based object to receive 
signals. Use another QObject.

-- 
 [ signature omitted ] 

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