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. How Connect signal slot correctly?
Qt 6.11 is out! See what's new in the release blog

How Connect signal slot correctly?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 721 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.
  • I Offline
    I Offline
    isan
    wrote on last edited by
    #1

    I Connect signal and slot like this and I get this error (QObject::connect: No such slot) when run it , How can I fix it?

    .h:

    class RandomWalk : public QThread {
      Q_OBJECT
    public:
      typedef void DataHandler(void *param, double elapsedTime, double series0,
                               double series1);
    
      RandomWalk(DataHandler *handler, void *param);
      virtual ~RandomWalk();
    
    
    private:
      // Disable copying and assignment
      RandomWalk &operator=(const RandomWalk &);
      RandomWalk(const RandomWalk &);
    
      QSerialPort *serial;
    };
    

    .cpp:

    RandomWalk::RandomWalk(RandomWalk::DataHandler *handler, void *param)
        : stopThread(false), handler(handler), param(param) {
      serial = new QSerialPort(this);
      connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
    }
    
    eyllanescE 1 Reply Last reply
    0
    • I isan

      I Connect signal and slot like this and I get this error (QObject::connect: No such slot) when run it , How can I fix it?

      .h:

      class RandomWalk : public QThread {
        Q_OBJECT
      public:
        typedef void DataHandler(void *param, double elapsedTime, double series0,
                                 double series1);
      
        RandomWalk(DataHandler *handler, void *param);
        virtual ~RandomWalk();
      
      
      private:
        // Disable copying and assignment
        RandomWalk &operator=(const RandomWalk &);
        RandomWalk(const RandomWalk &);
      
        QSerialPort *serial;
      };
      

      .cpp:

      RandomWalk::RandomWalk(RandomWalk::DataHandler *handler, void *param)
          : stopThread(false), handler(handler), param(param) {
        serial = new QSerialPort(this);
        connect(serial, SIGNAL(readyRead()), this, SLOT(readData()));
      }
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @isan Where is readData defined? Also use connect(serial, &QSerialPort::readyRead, this, &RandomWalk::readData);

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      BDC_PatrickB 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Apart from @eyllanesc comments - you're using QThread wrong and for no reason - QSerialPort is async anyway without the need for a separate thread.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • eyllanescE eyllanesc

          @isan Where is readData defined? Also use connect(serial, &QSerialPort::readyRead, this, &RandomWalk::readData);

          BDC_PatrickB Offline
          BDC_PatrickB Offline
          BDC_Patrick
          wrote on last edited by BDC_Patrick
          #4

          as @eyllanesc mentioned..
          you need to define your slot in the header first.
          means:

          private slots:
          void readData();
          

          And do the functionality in the source file.

          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