Results 1 to 3 of 3

Thread: QSocketNotifier: Multiple socket notifiers for same socket 1312 and type Read QObject

  1. #1
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSocketNotifier: Multiple socket notifiers for same socket 1312 and type Read QObject

    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.

    Qt Code:
    1. void MainServer::incom() {
    2.  
    3. QTcpSocket * mySocket = mainServer.nextPendingConnection();
    4.  
    5. ServerThread * serverThread = new ServerThread(mySocket->socketDescriptor(), this);
    6. // connect(serverThread, SIGNAL(finished()), ServerThread, SLOT(deleteLater()));
    7. serverThread->start();
    8. }
    9.  
    10.  
    11.  
    12. /* thread's constructor */
    13. ServerThread::ServerThread(int socketDescriptor,QObject *parent)
    14. : QThread(parent)
    15. {
    16. fd=socketDescriptor;
    17. mySocket = new QTcpSocket();
    18. tcpSocket->setSocketDescriptor(fd);//according to Fortuneserverthread example
    19.  
    20.  
    21.  
    22.  
    23.  
    24. }
    25. //run method is protected
    26. void ServerThread::run()
    27. {
    28. connect(mySocket, SIGNAL(readyRead()), this, SLOT(dataRead()));
    29. 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&)));
    30. exec();
    31. }
    32.  
    33.  
    34. void FortuneServerThread::dataRead()
    35. {
    36.  
    37.  
    38. ....//read data from socket and emit a signal for example:
    39. ... emit writeLog(str.append("User is in System"));
    40.  
    41. quit();
    42.  
    43. }
    To copy to clipboard, switch view to plain text mode 

    @

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSocketNotifier: Multiple socket notifiers for same socket 1312 and type Read QOb

    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).

  3. The following user says thank you to ChrisW67 for this useful post:

    milli (22nd May 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSocketNotifier: Multiple socket notifiers for same socket 1312 and type Read QOb

    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!

Similar Threads

  1. Replies: 9
    Last Post: 13th October 2010, 14:09
  2. Replies: 0
    Last Post: 5th November 2009, 03:11
  3. socket notifiers cannot be enabled from another thread
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2009, 15:15
  4. QSocketNotifier: Invalid socket 12 and type 'Read', disabling...
    By kunalnandi in forum General Programming
    Replies: 1
    Last Post: 24th September 2008, 18:09
  5. Replies: 10
    Last Post: 20th March 2007, 22:19

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.