Results 1 to 7 of 7

Thread: QSocketNotifier Issue

  1. #1
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Question QSocketNotifier Issue

    Is there any way to disable the default QSocketNotifier in windows? I have a Qt application that fails when stopped in Window, but succeeds in red hat. The only big difference that I can detect is the QSocketNotifier issue.

    Thank You

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSocketNotifier Issue

    Notes for Windows Users The socket passed to QSocketNotifier will become non-blocking, even if it was created as a blocking socket. The activated() signal is sometimes triggered by high general activity on the host, even if there is nothing to read. A subsequent read from the socket can then fail, the error indicating that there is no data available (e.g., WSAEWOULDBLOCK). This is an operating system limitation, and not a bug in QSocketNotifier.
    To ensure that the socket notifier handles read notifications correctly, follow these steps when you receive a notification:
    1. Disable the notifier.
    2. Read data from the socket.
    3. Re-enable the notifier if you are interested in more data (such as after having written a new command to a remote server).
    To ensure that the socket notifier handles write notifications correctly, follow these steps when you receive a notification:
    1. Disable the notifier.
    2. Write as much data as you can (before EWOULDBLOCK is returned).
    3. Re-enable notifier if you have more data to write.
    Further information: On Windows, Qt always disables the notifier after getting a notification, and only re-enables it if more data is expected. For example, if data is read from the socket and it can be used to read more, or if reading or writing is not possible because the socket would block, in which case it is necessary to wait before attempting to read or write again.
    So the only way of disabling that is to handle the first notification.
    But I am not sure if all things will be OK if you disable it permanently.

    Could you be more specific with the problem description?

    Regards

  3. #3
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSocketNotifier Issue

    What I think is going on is the following:

    I start the transmitting and receiving of information on their respective threads. When I stop, I wait for the QTcpServer and QTcpSocket to stop before I delete their class holders. The event loop is then given control and one extra QSocketNotifier issue is thrown. At this point, my thread is gone and I get an unhandled exception where QObject is attempting to access memory that doesn't belong to it (namely the pointer to the thread).

    Edit:

    How would I handle the default notifier issues? I am confused as I cannot even find out how to get a pointer to it.
    Last edited by TheGrimace; 18th July 2007 at 19:44.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSocketNotifier Issue

    OK. But I still don't understand from where the exception is coming from... From the GUI thread?

    About the other thing, getting a handle of the default socket notifier... well, you can't do that.

    Regards

  5. The following user says thank you to marcel for this useful post:

    TheGrimace (18th July 2007)

  6. #5
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSocketNotifier Issue

    All right. I am a little confused. How can I ignore something that I can't point to?

    As for the exception:

    When looking at the stack trace. It appears that the first call comes from threadex() and propogates through Qt libraries until it reaches the QEventHandler which calls QSocketNotifier which calls the QObject library. Here it tries to return a pointer to a unallocated area of memory.

    Thank you for the information you are providing

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSocketNotifier Issue

    I do not believe the problem lies in QSocketNotifier. It must be something else.
    But, as usually, your descriptions are very vague .

    If the worker thread is stopped(and deleted I assume), then why another thread's event dispatcher owns a socket notifier for your dead thread?

    The socket notifier for a worker thread should be owned by the thread's event dispatcher.
    Perhaps this is another thread problem.

    This is as much as I can say(actually, mostly assume) based on your post.

    Regards

  8. #7
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSocketNotifier Issue

    Well, I am accessing the sockets from another thread for reading and writing. The QSocketNotifier complains about this, but it still works. Afterward, I do not delete the thread that accessed these members, only the one which created them.

    I apologize that I am not more clear. I would show code, but as I have stated in other posts: most of the time I am asking about code which belongs to my company and not to me. And they have issues with my posting any part of it. I can, however, try to paint a layout of the objects involved:

    GUI
    |
    \/
    Main Thread
    |
    \/
    Another Thread
    / \
    \/ \/
    TCPServer TCPClient

    The QTcpServer and QTcpClients are created in TCPServer and TCPClient respectively. They are accessed from "Another Thread" for reading and writing.

    It is a blocking TCP design like Fortune Server Blocking example.

    Everything works until I stop. When I stop. I wait for everything to disconnect and then delete TCPServer and TCPClient. and stop the run method of "Another Thread"

    After all of this has happened and Qt gets the event loop back, the QSocketNotifier is called by threadex.

Similar Threads

  1. QtPlugin compile issue
    By croland in forum Qt Programming
    Replies: 2
    Last Post: 25th May 2007, 16:37
  2. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59
  3. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54
  4. Replies: 5
    Last Post: 22nd September 2006, 08:04
  5. A Design Issue...
    By nupul in forum Qt Programming
    Replies: 6
    Last Post: 4th May 2006, 17:41

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.