Unsolved QT QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
-
@J.Hilk thanks , I'll definitely look into it. Thanks again.
-
@J.Hilk thnaks , after doing some changes to this code , I no longer see those warnings in client code...but client doesn't read untill I write something(using cin.readline() function). Is there a way through which client doesn't wait to write something and reads the message from other client, in short it doesn't get blocked in writing.
-
@JadeN001 ready read is emitted as soon as data is available at the socket.
The fact that you only get data when you write something has nothing to do with qt, but with the server you connect to.
Change the server you have, so that he sends without beeing triggered first. A Timer for example.
-
@JadeN001 said in QT QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread:
text=cin.readLine();
Isn't that a blocking operation ? If so, the event loop is blocked until you get something from stdin.
-
@J.Hilk My server is just sending message when it arrives from client.i think at client side, i have to change the logic of calling write() function only when if there is no data in buffer for reading..I have tried to use bytesavailable().but it is not working.Do you have any idea about it?
-
@SGaist yes , that too is causing trouble. can you suggest any nonblocking userinput method? I'm really stuck at this point , SocketNotifier warning and this cin.readLine().
-
It would rather be: do your blocking input in one thread and manage your network in another one.
-
-
You might be interested by this small example for reading std using Qt.
-
@SGaist thanks very much
I tried this way too, but here I must pass the socketDescriptor as a parameter in QSocketNotifier. Its a bit confusing on client side how we can get socketDescriptor as in my knowledge we can only get socketdescriptor at serverside because of its Incommingconnection(). now, One more thing....Is it possible to get a warning of socket Notifier because reading and writing functions are being called at the same time ??
-
The socket notifier was only for stdin. As for your client side network connection, do everything in your dedicated worker object.