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] client can't disconnect user from server
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] client can't disconnect user from server

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.6k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    From the client, how to disconnect to the server? in the code below, the pushbutton when clicked should disconnect the server with socket->close(); but it does not. is socket->close(); server side only. if so, what would be the alternative to disconnect the user from client side?

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    socket = new QTcpSocket(this);

    this->connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
    this->connect(socket, SIGNAL(connected()), this, SLOT(connected()));

    socket->connectToHost(serverAddress, 4200);

    if (socket->waitForConnected(500))
    {
       ui->roomTextEdit->append("Connected to server ;-)");
       ui->connect->setText("Disconnect");
    
    } else {
       ui->roomTextEdit->append("Cannot connect to server");
       ui->connect->setText("Connect");
     }
    

    }

    void MainWindow::on_connect_clicked()
    {
    if (connected1 == 0)
    if (ui->connect->text() == "Connect"){
    login->show();
    ui->connect->setText("Disconnect");
    } else {
    if (connected1 == 1)
    socket->close();
    ui->connect->setText("Connect");
    }
    }@

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalster
      wrote on last edited by
      #2

      i found what i was looking for. the disconnectFromHost() disconnects the client from the host.

      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