1、QTcpSocket 继承于QAbstractSocket继承于QIODevice
2、QTcpSocket 提供的几种接收和发送数据方法
- write ( const char *, qint64 ) :
qint64
- write ( const char * ) : qint64
- write ( const QByteArray & ) :
qint64
- writeData ( const char *, qint64 ) :
qint64
- read ( char * data, qint64 maxSize
): qint64
- read ( qint64 maxSize ):QByteArray
- readAll ():QByteArray
- readLine ( char * data, qint64 maxSize
):qint64
- readLine ( qint64 maxSize = 0
):QByteArray
3、例子1 write ( const QByteArray & ) :
qint64
-
- QByteArray block;
-
- QDataStream out(&block,QIODevice::ReadWrite);
-
- out.setVersion(QDataStream::Qt_4_6);
-
-
- out << (quint16) 0;
-
- out<<hash;
-
-
- out.device()->seek(0);
-
- out << (quint16) (block.size()-sizeof(quint16));
-
-
- tcpSocket->write(block);
3、例子2 write ( const char *, qint64 ) :
qint64
- QString *a=new QString;
- tcpSocket->write(a,a->length());
4、例子3 数据流直接使用QIODevice
- QDataStream in(tcpSocket);
- in<< quint16(0xFFFF);
-
- quint16 length = 0;
- QDataStream out(tcpSocket);
- out >> length;
QTcpSocket 发送数据的几种方法,布布扣,bubuko.com
QTcpSocket 发送数据的几种方法
原文:http://www.cnblogs.com/lvdongjie/p/3758104.html