Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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


  • Lifetime Qt Champion

    @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...



  • can u elaborate ???
    tried

    SLOT(void indata())
    same error



  • @mganesh

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



  • @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.


Log in to reply