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. QObject::connect: No such slot MainWindow::indata()
Forum Updated to NodeBB v4.3 + New Features

QObject::connect: No such slot MainWindow::indata()

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 2.0k 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.
  • M Offline
    M Offline
    mganesh
    wrote on last edited by
    #1

    This is my program foe simple client side receiver
    here signal slot error coming out
    QObject::connect: No such slot MainWindow::indata()

    Folowing main cpp prgram

    **#include "mainwindow.h"
    #include<stdlib.h>
    #include "QTime"
    #include "QTimer"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    // QTimer *timer = new QTimer(this);
    clientsocket=new QTcpSocket(this);
    clientsocket->connectToHost("127.0.0.1",2555,QIODevice::ReadWrite);
    if (clientsocket->waitForConnected(300000))
    {
    ui->textEdit->setText("Connected to Server");
    clientsocket->write("server\r\n\r\n\r\n\r\n");
    clientsocket->waitForBytesWritten(1000);

    }
    else
    {
        ui->textEdit->setText("Server Offline");
      clientsocket->disconnectFromHost();
      clientsocket->close();
    }
    connect(clientsocket,SIGNAL(readyRead()),this,SLOT(indata()));
    connect(clientsocket,SIGNAL(disconnected()),this,SLOT(lineStatus()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::lineStatus()
    {
    ui->textEdit->setText("Server Disconnected");
    }

    void MainWindow::indata()
    {
    QByteArray array;

     qDebug() << "Reading: " << clientsocket->bytesAvailable();
     qDebug() <<"sec"<< clientsocket->readAll();
    array=clientsocket->readAll();
    char* buffer = array.data();
    
    ui->textEdit_3->setText(buffer);
    

    QByteArray ba_as_hex_string = array.toHex();

    qDebug()<<ba_as_hex_string;
    

    }

    void MainWindow::on_pushButton_2_clicked()
    {
    QString data;
    data=ui->textEdit_2->toPlainText();
    QByteArray abc;
    abc=data.toUtf8();
    // qDebug()<<abc;
    clientsocket->write(abc);
    clientsocket->flush();

    }**

    Header file

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include<QTcpSocket>
    #include<QTcpServer>
    #include<QString>
    #include<QtNetwork>
    #include <QIODevice>
    #include<QAbstractSocket>
    #include <QObject>

    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    QTcpSocket  *clientsocket;
    
    
    void indata();
    
    
    void lineStatus();
    

    private slots:
    void on_pushButton_2_clicked();

    private:
    Ui::MainWindow *ui;

    };
    #endif // MAINWINDOW_H

    jsulmJ 1 Reply Last reply
    0
    • M mganesh

      This is my program foe simple client side receiver
      here signal slot error coming out
      QObject::connect: No such slot MainWindow::indata()

      Folowing main cpp prgram

      **#include "mainwindow.h"
      #include<stdlib.h>
      #include "QTime"
      #include "QTimer"
      #include "ui_mainwindow.h"

      MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      // QTimer *timer = new QTimer(this);
      clientsocket=new QTcpSocket(this);
      clientsocket->connectToHost("127.0.0.1",2555,QIODevice::ReadWrite);
      if (clientsocket->waitForConnected(300000))
      {
      ui->textEdit->setText("Connected to Server");
      clientsocket->write("server\r\n\r\n\r\n\r\n");
      clientsocket->waitForBytesWritten(1000);

      }
      else
      {
          ui->textEdit->setText("Server Offline");
        clientsocket->disconnectFromHost();
        clientsocket->close();
      }
      connect(clientsocket,SIGNAL(readyRead()),this,SLOT(indata()));
      connect(clientsocket,SIGNAL(disconnected()),this,SLOT(lineStatus()));
      

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }

      void MainWindow::lineStatus()
      {
      ui->textEdit->setText("Server Disconnected");
      }

      void MainWindow::indata()
      {
      QByteArray array;

       qDebug() << "Reading: " << clientsocket->bytesAvailable();
       qDebug() <<"sec"<< clientsocket->readAll();
      array=clientsocket->readAll();
      char* buffer = array.data();
      
      ui->textEdit_3->setText(buffer);
      

      QByteArray ba_as_hex_string = array.toHex();

      qDebug()<<ba_as_hex_string;
      

      }

      void MainWindow::on_pushButton_2_clicked()
      {
      QString data;
      data=ui->textEdit_2->toPlainText();
      QByteArray abc;
      abc=data.toUtf8();
      // qDebug()<<abc;
      clientsocket->write(abc);
      clientsocket->flush();

      }**

      Header file

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QMainWindow>
      #include<QTcpSocket>
      #include<QTcpServer>
      #include<QString>
      #include<QtNetwork>
      #include <QIODevice>
      #include<QAbstractSocket>
      #include <QObject>

      QT_BEGIN_NAMESPACE
      namespace Ui { class MainWindow; }
      QT_END_NAMESPACE

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();

      QTcpSocket  *clientsocket;
      
      
      void indata();
      
      
      void lineStatus();
      

      private slots:
      void on_pushButton_2_clicked();

      private:
      Ui::MainWindow *ui;

      };
      #endif // MAINWINDOW_H

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mganesh said in QObject::connect: No such slot MainWindow::indata():

      void indata();

      This needs to be in slots: part of your class to be a slot...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mganesh
        wrote on last edited by
        #3

        can u elaborate ???
        tried

        SLOT(void indata())
        same error

        Pl45m4P JonBJ 2 Replies Last reply
        -1
        • M mganesh

          can u elaborate ???
          tried

          SLOT(void indata())
          same error

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @mganesh

          indata() and lineStatus() belong to slots: section in your header file.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          3
          • M mganesh

            can u elaborate ???
            tried

            SLOT(void indata())
            same error

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @mganesh

            1. Please read through https://doc.qt.io/qt-5/signalsandslots.html, looking at the examples.

            2. Please move away from SIGNAL/SLOT() macros, which are very old, and use the "new" syntax described there.

            1 Reply Last reply
            3

            • Login

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