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. Problem with Signal and SLOTS
Forum Updated to NodeBB v4.3 + New Features

Problem with Signal and SLOTS

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 304 Views 2 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.
  • C Offline
    C Offline
    Chaki
    wrote on last edited by
    #1

    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";
    }
    
    
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      3
      • C Chaki

        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";
        }
        
        
        
        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

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

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • SGaistS SGaist

          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.

          C Offline
          C Offline
          Chaki
          wrote on last edited by
          #4

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

          jsulmJ 1 Reply Last reply
          0
          • C Chaki

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

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

            @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

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

            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