I can not receive simple int values over a socket



  • Hi,
    I use a tcp socket with a signal slot mechanism to send and receive messages from a java socket server.
    My problem is the function readReady will just called if I send a string. But I want to send and receive an int.
    Is there an way to do it? Or can i just receive strings?

    My code:

    connect(socket,SIGNAL(readyRead()),this,SLOT(readReady()));
    
    void TcpSocketCon::readReady()
    {
        qDebug()<<"Read from Socket";
        qDebug()<<socket->readAll();
    }
    

  • Moderators

    In which way is your int send?
    If it is sent binary, you will have to extract it from your buffer. There is no automatic conversion. With QByteArray you may use toInt() However, you need to know the information type to be received.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.