Ejemplo n.º 1
0
void qt_flushOutBuffer()
{
	if (!qt_initialized)
		return;

	// Write the block size at the beginning of the bock
	QDataStream sizeStream(&qt_socket);
	sizeStream << (quint32)(qt_outBuffer.size());
	// Write the block to the QLocalSocket
	qt_socket.write(qt_outBuffer);
	// waitForBytesWritten(-1) is supposed implement this loop, but it does not seem to work !
	// update: seems to work with Qt 4.5
	while (qt_socket.bytesToWrite() > 0)
	{
		qt_socket.flush();
		qt_socket.waitForBytesWritten(-1);
	}
	// Reset the buffer
	qt_out.device()->seek(0);
	qt_outBuffer.clear();
}
Ejemplo n.º 2
0
void qt_flushOutBuffer()
{
    if (!qt || !qt->socket.isValid())
        return;

    // Write the block size at the beginning of the block
    QDataStream sizeStream(&qt->socket);
    sizeStream << (quint32)(qt->outBuffer.size());
    // Write the block to the QLocalSocket
    qt->socket.write(qt->outBuffer);
    // waitForBytesWritten(-1) is supposed implement this loop, but it does not seem to work !
    // update: seems to work with Qt 4.5 on Linux and Qt 5.1 on Windows, but not on Mac
    while (qt->socket.bytesToWrite() > 0)
    {
        qt->socket.flush();
        // Avoid dead-locking when no more data is available
        if (qt->socket.bytesToWrite() > 0)
            qt->socket.waitForBytesWritten(-1);
    }
    // Reset the buffer
    qt->out.device()->seek(0);
    qt->outBuffer.clear();
}