PDA

View Full Version : QSocketNotifier: Multiple socket notifiers for same socket 1312 and type Read QObject



milli
21st May 2011, 20:29
I am working on a server-client application,i spent in a lot of hours to understand why the application is terminated in an unusual way.Well,the problem was that,firstly connect methods, that now are defined in run method,were defined in the thread's constructor.Now application is not terminated.
The problem is these warnings:

QSocketNotifier: Multiple socket notifiers for same socket 1172 and type Read:
Can you explain me why this warning diplayed?
without this command:tcpSocket->setSocketDescriptor(fd);
tcpsocket's socketdescriptor in the thread constructor is -1 .


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

Can you give an example:i have read the documentation and i tried
qRegisterMetaType<Qt::GlobalColor>(Qt::GlobalColor); but this command gave errors at compilation time.



void MainServer::incom() {

QTcpSocket * mySocket = mainServer.nextPendingConnection();

ServerThread * serverThread = new ServerThread(mySocket->socketDescriptor(), this);
// connect(serverThread, SIGNAL(finished()), ServerThread, SLOT(deleteLater()));
serverThread->start();
}



/* thread's constructor */
ServerThread::ServerThread(int socketDescriptor,QObject *parent)
: QThread(parent)
{
fd=socketDescriptor;
mySocket = new QTcpSocket();
tcpSocket->setSocketDescriptor(fd);//according to Fortuneserverthread example





}
//run method is protected
void ServerThread::run()
{
connect(mySocket, SIGNAL(readyRead()), this, SLOT(dataRead()));
connect(this, SIGNAL(writeLog(QString, int, int, int, Qt::GlobalColor)), (mServer *)(this->parent()), SLOT(writeLog(const QString&, const int&, const int&, const int&, const Qt::GlobalColor&)));
exec();
}


void FortuneServerThread::dataRead()
{


....//read data from socket and emit a signal for example:
... emit writeLog(str.append("User is in System"));

quit();

}

@

ChrisW67
22nd May 2011, 02:30
At line 17-18 of your listing you are referring to different QTcpSockets: deliberate or not? Do you intend doing anything with "mySocket"? Where does "tcpsocket" come from? If "tcpsocket" is some shared variable and you create several ServerThread objects then when you setSocketDescriptor() the second time you might trigger a warning (this is an educated guess).

Qt::GlobalColor is an enum. You cannot register an enum using qRegisterMetaType because:

Any class or struct that has a public default constructor, a public copy constructor and a public destructor can be registered.
If you want to send the value of the enum then use int, or try sending a QColor (you can construct one from the Qt::GlobalColor value).

milli
22nd May 2011, 21:31
At line 17-18 of your listing you are referring to different QTcpSockets: deliberate or not? Do you intend doing anything with "mySocket"? Where does "tcpsocket" come from? If "tcpsocket" is some shared variable and you create several ServerThread objects then when you setSocketDescriptor() the second time you might trigger a warning (this is an educated guess).[


Yes "tcpsocket" is a shared variable and i create several ServerThread objects setting the socket descriptor (line 3) to new sockets (mySocket) which will serve incoming connections from clients.As i understand i have one socket descriptor fow two sockets and this triggers a warning.However it is not an error.
Right?

Thanks a lot for your answers!