Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QTcpSocket signals problem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTcpSocket signals problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 534 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RdoEgito
    wrote on last edited by
    #1

    Hi,

    I'm having trouble with QTcpSocket signals. I'm using QTcpSocket::write() to request the server some data and trying to use the signal readyRead() to receive those data, but it doesn't work. I tried to using others signals (just for test) and none of those work.

    Here is my code:

    In the constructor I have:
    @
    buffer = new QBuffer(this);
    socket = new QTcpSocket(this);
    buffer->open(QIODevice::ReadWrite);

    connect(socket, SIGNAL(readyRead()), SLOT(receiveMessage()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
    SLOT(mostrarErro(QAbstractSocket::SocketError)));@

    The function to connect to the host:

    @void Client::connectToServer()
    {
    Settings::ConnectionData p = c->data(); //ConnectionData is a struct to receive the Data from other form and c is the other form class object

    socket = p.socket;
    port = p.port;
    buffer = p.buffer;
    
    if (socket->state() == QAbstractSocket::UnconnectedState) {
        socket->connectToHost(setIp(), port);
    }
    else {
        socket->disconnectFromHost();
    }
    

    }@

    I'm sure that the function receiveMessage() is not being called.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RdoEgito
      wrote on last edited by
      #2

      I just realized that I was connecting my socket with another socket (p.sockets).

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved