Results 1 to 1 of 1

Thread: QTCPSockets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTCPSockets

    I am having trouble with using TCP sockets in QT. I have opened a socket for reading and writing and when it tries to write I get the message "QNativeSocketEngine::write() was not called in QAbstractSocket::ConnectState" over and over. Before I write I check what state it is in and it is showing QAbstractState::Connected which is value 3 being printed out. How come it is having trouble writing on the socket. Here is the code I am using for wrting on the socket. I am writing in Windows and it runs ok, then I bring the code over to CentOS and it compiles ok but when I run the application it runs into this problem. Any help would be appreciated.

    Qt Code:
    1. .
    2. .
    3. .
    4. tcpSocket1 = new QTcpSocket();
    5. tcpSocket1->connectToHost("192.168.0.101", 800, QIODevice::ReadWrite);
    6. if(tcpSocket1->socketDescriptor() > 0)
    7. tcpSocket = tcpSocket1;
    8.  
    9. if (!tcpSocket->waitForConnected(Timeout))
    10. return;
    11.  
    12. connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(read_data()));
    13. connect( tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
    14. .
    15. .
    16. .
    17.  
    18. void Common::send_sock_data_1(int G_sock_data_len)
    19. {
    20. int byte_send = 0;
    21.  
    22. if(tcpSocket == NULL) return;
    23. qDebug("TCP socket is %d\n", tcpSocket->state());
    24. if(tcpSocket->state() != QAbstractSocket::ConnectedState ) return;
    25.  
    26. if ( tcpSocket->isValid() )
    27. {
    28. byte_send = tcpSocket->write(G_sock_data_1, G_sock_data_len);
    29. .
    30. .
    31. .
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 6th August 2008 at 18:28. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 25th February 2008, 10:36
  2. QTcpSockets and QThreads
    By TheRonin in forum Newbie
    Replies: 3
    Last Post: 21st June 2006, 09:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.