📄 qsocket.3qt
字号:
The bytesToWrite() function is often used in the same context; it indicates how many buffered bytes there are left to write..PPSee also writeBlock() and bytesToWrite()..SH "bool QSocket::canReadLine () const"Returns TRUE if it's possible to read an entire line of text from this socket at this time; otherwise returns FALSE..PPNote that if the peer closes the connection unexpectedly, this function returns FALSE. This means that loops such as this won't work:.PP.nf.br while( !socket->canReadLine() ) // WRONG..br ....br.fi.PPSee also readLine()..PPExamples:.)l network/clientserver/client/client.cpp, network/httpd/httpd.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::clearPendingData ()"Deletes the data that is waiting to be written. This is.PPSee also bytesToWrite() and close()..SH "void QSocket::close ()\fC [virtual]\fR"Closes the socket..PPThe read buffer is cleared..PPIf the output buffer is empty, the state is set to QSocket::Idle and the connection is terminated immediately. If the output buffer still contains data to be written, QSocket goes into the QSocket::Closing state and the rest of the data will be written. When all of the outgoing data have been written, the state is set to QSocket::Idle and the connection is terminated. At this point, the delayedCloseFinished() signal is emitted..PPIf you don't want that the data of the output buffer is written, call clearPendingData() before you call close()..PPSee also state(), bytesToWrite(), and clearPendingData()..PPExamples:.)l network/clientserver/client/client.cpp, network/httpd/httpd.cpp, and network/networkprotocol/nntp.cpp..PPReimplemented from QIODevice..SH "void QSocket::connectToHost ( const QString & host, Q_UINT16 port )\fC [virtual]\fR"Attempts to make a connection to \fIhost\fR on the specified \fIport\fR and return immediately..PPAny connection or pending connection is closed immediately, and QSocket goes into the HostLookup state. When the lookup succeeds, it emits hostFound(), starts a TCP connection and goes into the Connecting state. Finally, when the connection succeeds, it emits connected() and goes into the Connected state. If there is an error at any point, it emits error()..PP\fIhost\fR may be an IP address in string form, or it may be a DNS name. QSocket will do a normal DNS lookup if required. Note that \fIport\fR is in native byte order, unlike some other libraries..PPSee also state()..PPExamples:.)l network/clientserver/client/client.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::connected ()\fC [signal]\fR"This signal is emitted after connectToHost() has been called and a connection has been successfully established..PPSee also connectToHost() and connectionClosed()..PPExamples:.)l network/clientserver/client/client.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::connectionClosed ()\fC [signal]\fR"This signal is emitted when the other end has closed the connection. The read buffers may contain buffered input data which you can read after the connection was closed..PPSee also connectToHost() and close()..PPExamples:.)l network/clientserver/client/client.cpp, network/clientserver/server/server.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::delayedCloseFinished ()\fC [signal]\fR"This signal is emitted when a delayed close is finished..PPIf you call close() and there is buffered output data to be written, QSocket goes into the QSocket::Closing state and returns immediately. It will then keep writing to the socket until all the data has been written. Then, the delayedCloseFinished() signal is emitted..PPSee also close()..PPExamples:.)l network/clientserver/client/client.cpp and network/httpd/httpd.cpp..SH "void QSocket::error ( int )\fC [signal]\fR"This signal is emitted after an error occurred. The parameter is the Error value..PPExamples:.)l network/clientserver/client/client.cpp and network/networkprotocol/nntp.cpp..SH "void QSocket::flush ()\fC [virtual]\fR"Implementation of the abstract virtual QIODevice::flush() function..PPReimplemented from QIODevice..SH "int QSocket::getch ()\fC [virtual]\fR"Reads a single byte/character from the internal read buffer. Returns the byte/character read, or -1 if there is nothing to be read..PPSee also bytesAvailable() and putch()..PPReimplemented from QIODevice..SH "void QSocket::hostFound ()\fC [signal]\fR"This signal is emitted after connectToHost() has been called and the host lookup has succeeded..PPSee also connected()..PPExample: network/networkprotocol/nntp.cpp..SH "bool QSocket::open ( int m )\fC [virtual]\fR"Opens the socket using the specified QIODevice file mode \fIm\fR. This function is called automatically when needed and you should not call it yourself..PPSee also close()..PPReimplemented from QIODevice..SH "QHostAddress QSocket::peerAddress () const"Returns the host address as resolved from the name specified to the connectToHost() function..SH "QString QSocket::peerName () const"Returns the host name as specified to the connectToHost() function. An empty string is returned if none has been set..PPExample: network/mail/smtp.cpp..SH "Q_UINT16 QSocket::peerPort () const"Returns the peer's host port number, normally as specified to the connectToHost() function. If none has been set, this function returns 0..PPNote that Qt always uses native byte order, i.e. 67 is 67 in Qt; there is no need to call htons()..SH "Q_UINT16 QSocket::port () const"Returns the host port number of this socket, in native byte order..SH "int QSocket::putch ( int ch )\fC [virtual]\fR"Writes the character \fIch\fR to the output buffer..PPReturns \fIch\fR, or -1 if an error occurred..PPSee also getch()..PPReimplemented from QIODevice..SH "Q_LONG QSocket::readBlock ( char * data, Q_ULONG maxlen )\fC [virtual]\fR"Reads \fImaxlen\fR bytes from the socket into \fIdata\fR and returns the number of bytes read. Returns -1 if an error occurred..PPExample: network/networkprotocol/nntp.cpp..PPReimplemented from QIODevice..SH "QString QSocket::readLine ()\fC [virtual]\fR"Returns a line of text including a terminating newline character (\\n). Returns "" if canReadLine() returns FALSE..PPSee also canReadLine()..PPExamples:.)l network/clientserver/client/client.cpp, network/httpd/httpd.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::readyRead ()\fC [signal]\fR"This signal is emitted every time there is new incoming data..PPBear in mind that new incoming data is only reported once; if you do not read all the data, this class buffers the data and you can read it later, but no signal is emitted unless new data arrives. A good practice is to read all data in the slot connected to this signal unless you are sure that you need to receive more data to be able to process it..PPSee also readBlock(), readLine(), and bytesAvailable()..PPExamples:.)l network/clientserver/client/client.cpp, network/httpd/httpd.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp..SH "void QSocket::setSocket ( int socket )\fC [virtual]\fR"Sets the socket to use \fIsocket\fR and the state() to Connected. The socket must already be connected..PPThis allows us to use the QSocket class as a wrapper for other socket types (e.g. Unix Domain Sockets)..PPExample: network/httpd/httpd.cpp..SH "void QSocket::setSocketDevice ( QSocketDevice * device )\fC [virtual]\fR"Sets the internal socket device to \fIdevice\fR. Passing a \fIdevice\fR of 0 will cause the internal socket device to be used. Any existing connection will be disconnected before using the new \fIdevice\fR..PPThe new device should not be connected before being associated with a QSocket; after setting the socket call connectToHost() to make the connection..PPThis function is useful if you need to subclass QSocketDevice and want to use the QSocket API, for example, to implement Unix domain sockets..SH "Offset QSocket::size () const\fC [virtual]\fR"Returns the number of incoming bytes that can be read right now (like bytesAvailable())..PPReimplemented from QIODevice..SH "int QSocket::socket () const"Returns the socket number, or -1 if there is no socket at the moment..SH "QSocketDevice * QSocket::socketDevice ()"Returns a pointer to the internal socket device..PPThere is normally no need to manipulate the socket device directly since this class does the necessary setup for most applications..SH "State QSocket::state () const"Returns the current state of the socket connection..PPSee also QSocket::State..PPExamples:.)l network/clientserver/client/client.cpp and network/networkprotocol/nntp.cpp..SH "int QSocket::ungetch ( int ch )\fC [virtual]\fR"This implementation of the virtual function QIODevice::ungetch() prepends the character \fIch\fR to the read buffer so that the next read returns this character as the first character of the output..PPReimplemented from QIODevice..SH "Q_ULONG QSocket::waitForMore ( int msecs, bool * timeout ) const"Wait up to \fImsecs\fR milliseconds for more data to be available..PPIf \fImsecs\fR is -1 the call will block indefinitely..PPReturns the number of bytes available..PPIf \fItimeout\fR is non-null and no error occurred (i.e. it does not return -1): this function sets \fI*timeout\fR to TRUE, if the reason for returning was that the timeout was reached; otherwise it sets \fI*timeout\fR to FALSE. This is useful to find out if the peer closed the connection..PP\fBWarning:\fR This is a blocking call and should be avoided in event driven applications..PPSee also bytesAvailable()..SH "Q_ULONG QSocket::waitForMore ( int msecs ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "Q_LONG QSocket::writeBlock ( const char * data, Q_ULONG len )\fC [virtual]\fR"Writes \fIlen\fR bytes to the socket from \fIdata\fR and returns the number of bytes written. Returns -1 if an error occurred..PPExample: network/networkprotocol/nntp.cpp..PPReimplemented from QIODevice..SH "SEE ALSO".BR http://doc.trolltech.com/qsocket.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsocket.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -