[Qt-creator] Regarding QByteArray

Andre Poenitz andre.poenitz at mathematik.tu-chemnitz.de
Sun May 24 17:36:46 CEST 2009


On Sun, May 24, 2009 at 06:29:39PM +0300, Kosta wrote:
> Hello, Does anyone know how to remove the \0 character from the end my
> this array ?

You do not have to do that.
> 
> Although the size() is 5, the byte array also maintains an extra '\0'
> character at the end so that if a function is used that asks for a
> pointer to the underlying data (e.g. a call to data()), the data
> pointed to is guaranteed to be '\0'-terminated.
> 
> I have to send some bytes trought the wire and I think this \0 will
> cause a problem if I send it. I'm using UDP, so I will use the
> writeDatagram method of QUdpSocket.  Actually I'm sending SNMP
> message. 

It's 

	QUdpSocket::writeDatagram(const char *data, qint64 size, const
	QHostAddress &address, quint16 port)

so

	writeDatagram(ba, ba.size(), address, port)

should just work.

Andre'



More information about the Qt-creator-old mailing list