Re: problem with QTcpSocket
Maybe the database causes the disconnection? My guess is that you shouldn't use QDataStream, it does something more than just stream the data. Try using QTextStream instead.
Anyway, maybe you should write your own database driver for that database?
Re: problem with QTcpSocket
Hi,
first thanks for your answer. You are the first in 3 forums who gives me a hint :D in 4 days!
I try to use QTextStream and write what happens. -> Must I chance QByteArray ?
Thanks,
SuperSonik
Re: problem with QTcpSocket
Hi,
I once again :) . How can I write with QTextStream on QTcpSocket?:confused:
Can someone give me an example?
Greetings,
SuperSonik
Re: problem with QTcpSocket
Quote:
Originally Posted by
SuperSonik
You are the first in 3 forums who gives me a hint :D in 4 days!
As you see we have pretty good answer times here.
Quote:
I try to use QTextStream and write what happens. -> Must I chance QByteArray ?
Open the text stream to the byte array and stream the QString contents through. You should end up with a byte array which you can then pass to QTcpSocket::write().
Re: problem with QTcpSocket
Quote:
Originally Posted by
SuperSonik
Code:
void sendRequest(void) {
QString abfrage
("SELECT * FROM Datum; \r\n");
out << abfrage.toAscii();
out.device()->seek(0);
out << quint16(block.size() - sizeof(quint16));
tcpsocket.write(block);
pushButton_abfragen->setText(tcpsocket.errorString());
};//sendRequest
I'm not sure if this code is really what you wanted to do. toAscii() method converts QString to QByteArray. QByteArray written to QDataStream is represented as array size (quint32) followed by the array bytes. So in block variable you have something like this:
Code:
[x][x][x][x][S][E][L][E][C][T][...]
and then you rewind to position 0 and overwrite first two bytes:
Code:
[y][y][x][x][S][E][L][E][C][T][...]
Is this realy what you wanted?
Re: problem with QTcpSocket
Hi,
I'm not sure. I read a Qt book, and there I read I have to write the lenght of my message first
in my tcp package as a qint64.
I took the code out of the book and chance a few things.
In real I only want to send the string as I write it in the QString. -> exactly this String
I thought to write the lenght before the message is something I have to do because of tcp.
Greetings,
SuperSonik
Re: problem with QTcpSocket
Take a look at the docs, you'll notice the write() method that takes a byte array as its argument (it's probably defined in QIODevice class).
Re: problem with QTcpSocket
Ok,
I have found my problem. I think my programm is working for a while.
The error message was wrong. If I call tcpsocket.errorString() and there is no error the funktion returns "Unknown error".
Now it's working. Thank you to all.
Greetings,
SuperSonik