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. undefined reference on emit function
Forum Updated to NodeBB v4.3 + New Features

undefined reference on emit function

Scheduled Pinned Locked Moved Unsolved General and Desktop
threademit signalconnect
4 Posts 3 Posters 619 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.
  • J Offline
    J Offline
    JuanNunez
    wrote on 13 Feb 2023, 15:05 last edited by
    #1

    Hello, I have a proyect with a thread and a listWidget, the problem is when I use emit, the error is: "undefined reference to `hiloDelSocket::datos(QString)'", but I declered it on the header.

    void hiloDelSocket::run(){
        ZeroMemory(buffer,12);
        recv(sock,buffer,12,0);
        const QString a = buffer;
        emit datos(a); //error
    }
    
    //header
    class hiloDelSocket: public QThread
    {
    
        Q_OBJECT //I have to use it because otherwise it gives me other error
    
    public:
        hiloDelSocket(QObject *parent = nullptr);
    
    signals:
        void datos(const QString); //here is declarated
    
    protected:
        void run() override;
    
    private:
        char buffer[12];
        SOCKET sock;
    
    };
    
    J 2 Replies Last reply 13 Feb 2023, 15:40
    0
    • J JuanNunez
      13 Feb 2023, 15:05

      Hello, I have a proyect with a thread and a listWidget, the problem is when I use emit, the error is: "undefined reference to `hiloDelSocket::datos(QString)'", but I declered it on the header.

      void hiloDelSocket::run(){
          ZeroMemory(buffer,12);
          recv(sock,buffer,12,0);
          const QString a = buffer;
          emit datos(a); //error
      }
      
      //header
      class hiloDelSocket: public QThread
      {
      
          Q_OBJECT //I have to use it because otherwise it gives me other error
      
      public:
          hiloDelSocket(QObject *parent = nullptr);
      
      signals:
          void datos(const QString); //here is declarated
      
      protected:
          void run() override;
      
      private:
          char buffer[12];
          SOCKET sock;
      
      };
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Feb 2023, 15:40 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 13 Feb 2023, 20:08 last edited by
        #3

        Hi,

        The usual signature of the such a signal is rather a const reference and not a const object.

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

        1 Reply Last reply
        0
        • J JuanNunez
          13 Feb 2023, 15:05

          Hello, I have a proyect with a thread and a listWidget, the problem is when I use emit, the error is: "undefined reference to `hiloDelSocket::datos(QString)'", but I declered it on the header.

          void hiloDelSocket::run(){
              ZeroMemory(buffer,12);
              recv(sock,buffer,12,0);
              const QString a = buffer;
              emit datos(a); //error
          }
          
          //header
          class hiloDelSocket: public QThread
          {
          
              Q_OBJECT //I have to use it because otherwise it gives me other error
          
          public:
              hiloDelSocket(QObject *parent = nullptr);
          
          signals:
              void datos(const QString); //here is declarated
          
          protected:
              void run() override;
          
          private:
              char buffer[12];
              SOCKET sock;
          
          };
          
          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 14 Feb 2023, 05:17 last edited by
          #4

          @JuanNunez I deleted my first response as I did not realised that it was about a signal and one does not have to implement a signal.
          Did you try a complete rebuild after adding signal? Delete build folder, run qmake and build.

          1 Reply Last reply
          0

          1/4

          13 Feb 2023, 15:05

          • Login

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