PDA

View Full Version : QNativeSocketEngine



Thunder
1st August 2008, 21:24
Hi I am encountering a problem with my program when it try to connect to another machine using QTCPSocket. I keep getting the message QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectState continuously at a very fast interval.
Below is some code I have to connect to a Server.


tcpSocket1 = new QTcpSocket();
tcpSocket1->connectToHost("192.168.0.101", 600, QIODevice::ReadWrite);
.
.
.
connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(read_data()));
connect( tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));

If there is anyone who can explain what is happening and what a solution is I would like to hear it.

Thanks

wysota
4th August 2008, 10:57
Is there more code related to the socket? Especially one related to writing to it?

Thunder
5th August 2008, 14:05
void Common::send_sock_data_1(int G_sock_data_len)
{
int byte_send;
byte_send = tcpSocket->write(G_sock_data_1, G_sock_data_len);
.
.
.

Here is my write function. I pass in an integer which represents the length of the message being sent. G_sock_data_1 is a char array. I would like to know what I am doing wrong, or if there is a better solution to write on a socket. Also I am porting code over from Windows to CentOS.

wysota
5th August 2008, 18:30
Did you wait for the socket to establish connection before writing the data to the socket?

Thunder
5th August 2008, 20:20
I have been using the same socket for reading in data, and it works fine, but when I want to be able to write on the same socket I keep getting that "QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectState" message over and over. When I run it under Windows it appears to work fine, but once I import to CentOS it doesn't work.

wysota
5th August 2008, 22:58
Could you prepare a minimal compilable example reproducing the problem?

chrismcfish
10th October 2008, 15:40
Just had this issue myself then eventually found out that the problem was that the server I was trying to connect to was down. Hadn't got as far as putting error checking in!

Hopefully that helps anyone else who stumbles on this thread via google. :)