Home >
other > Consult QSocketNotifier problem..
Consult QSocketNotifier problem..
I use QFile open a file, and then use QSocketNotifier to monitor its descriptor is readable, if activatied function to print a word into the trough, but the actual runtime, terminal constantly repeat print (continuously into the groove function), I am very strange, not to write anything file? If I go to read files, couldn't read anything,,, the code is as follows: Server: Server (QString fileName, QObject * parent) : QObject (parent) {file=new QFile (fileName, this); If (file - & gt; Open (QIODevice: : ReadWrite)) {if (file - & gt; The handle () & gt;=0) {notifier=new QSocketNotifier (file - & gt; Handle (), QSocketNotifier: : Write, this); Connect (notifier, SIGNAL (the activated (int)), and this, SLOT (onActivated (int))); }} else qDebug () & lt; <"The open file failed!" ; } voidServer: : onActivated (int) {char buf [32]. Int n=file - & gt; Read (buf, 31); QDebug () & lt; <"N=" & lt; CodePudding user response: Hello I also encountered such a problem found the reason