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. server to client send data
Forum Updated to NodeBB v4.3 + New Features

server to client send data

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 198 Views
  • 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.
  • E Offline
    E Offline
    ELIF
    wrote on last edited by
    #1

    I have two QT projects.One of them is for client other is for server.I add +network both

    pro files.I want to write something server to client.So I decided to write from server side , read from client side.

    In CLIENT SIDE constructor I have

    Client::Client()
    {
        tcpSocket = new QTcpSocket();
        tcpSocket->connectToHost(QHostAddress::LocalHost,45442);//Connection is OK
    connect(tcpSocket,&QTcpSocket::readyRead, this, &Client::readyRead);//Not working
    }
    

    In CLIENT SIDE readyRead()

    void Client::readyRead(){
        qDebug() << "///READYREAD SLOT///";
        qDebug() << tcpSocket->readAll();
    }
    

    In server side header file I have

    QTcpSocket *clientConnection;
    

    IN SERVER SIDE I HAVE :TimerSlot()

    void MainWindow::TimerSlot(){//
       clientConnection->write(QByteArray::fromStdString("ABCDEFFGHJKL"));
    }
    
    

    IN SERVER SIDE CONSTRUCTOR

    MainWindow::MainWindow (QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
     timerTarget = new QTimer(this);
    connect(timerTarget,SIGNAL(timeout()),this,SLOT(TimerSlot())); 
     timerTarget->start(700);//NOT WORKINNG All app is shutting down suddenly when I call this code line
    }
    

    So what is the problem? Where is my error?
    Thank you.

    J.HilkJ 1 Reply Last reply
    0
    • E ELIF

      I have two QT projects.One of them is for client other is for server.I add +network both

      pro files.I want to write something server to client.So I decided to write from server side , read from client side.

      In CLIENT SIDE constructor I have

      Client::Client()
      {
          tcpSocket = new QTcpSocket();
          tcpSocket->connectToHost(QHostAddress::LocalHost,45442);//Connection is OK
      connect(tcpSocket,&QTcpSocket::readyRead, this, &Client::readyRead);//Not working
      }
      

      In CLIENT SIDE readyRead()

      void Client::readyRead(){
          qDebug() << "///READYREAD SLOT///";
          qDebug() << tcpSocket->readAll();
      }
      

      In server side header file I have

      QTcpSocket *clientConnection;
      

      IN SERVER SIDE I HAVE :TimerSlot()

      void MainWindow::TimerSlot(){//
         clientConnection->write(QByteArray::fromStdString("ABCDEFFGHJKL"));
      }
      
      

      IN SERVER SIDE CONSTRUCTOR

      MainWindow::MainWindow (QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
      {
       timerTarget = new QTimer(this);
      connect(timerTarget,SIGNAL(timeout()),this,SLOT(TimerSlot())); 
       timerTarget->start(700);//NOT WORKINNG All app is shutting down suddenly when I call this code line
      }
      

      So what is the problem? Where is my error?
      Thank you.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @ELIF said in server to client send data:

      QTcpSocket *clientConnection

      where do you new/allocate this ?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      E 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @ELIF said in server to client send data:

        QTcpSocket *clientConnection

        where do you new/allocate this ?

        E Offline
        E Offline
        ELIF
        wrote on last edited by
        #3

        @J-Hilk said in server to client send data:

        clientConnection

        Thank you I forget it:) Now it is working.

        1 Reply Last reply
        1

        • Login

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