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

Problem with Signal and SLOTS



  • I have written the following code, but I just do not get the first instance of connect right:

    serialcomm.h
    
    signals:
    
    void write(QStringList Data);
    
    private:
      
            QByteArray mData;
    
    
    serialcomm.cpp
    
    void serialcomm::parseData()
    {
        QString ActualData(mData);
        qDebug() << ActualData;
        QStringList Data = ActualData.split("\\");
        qDebug() << Data;
        emit write(Data);
    
    }
    
    mainwindow.h
    
    private slots:
        void ReallyWrite(QStringList Data);
    
    mainwindow.cpp
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QStringList ports = serialcomm::getSerialPorts();
        ui->cmb_port->addItems(ports);
        connect(???, SIGNAL(write(Data)), this, SLOT(ReallyWrite(QStringList Data)));
    
    }
    void MainWindow::ReallyWrite(QStringList Data)
    {
        qDebug() << "Yeah";
    }
    
    
    

  • Lifetime Qt Champion

    Hi,

    You need a serialcomm instance to replace your "???".

    You should also change your signal and slot signature to use a const reference. This will avoid make useless copies of the data.



  • @Chaki said in Problem with Signal and SLOTS:

    connect(???, SIGNAL(write(Data)), this, SLOT(ReallyWrite(QStringList Data)));

    You may want to consider using the new syntax for signals & slots as it provides any errors about connections at compile time.



  • @SGaist
    Thank you for your reply sir. I am not quite sure in which header-file I should initialize a new serialcomm


  • Qt Champions 2019

    @Chaki said in Problem with Signal and SLOTS:

    I am not quite sure in which header-file I should initialize a new serialcomm

    You can do it in MainWindow


Log in to reply