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. Linking error compiling customListWidget on emitting signal
Forum Updated to NodeBB v4.3 + New Features

Linking error compiling customListWidget on emitting signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 207 Views
  • 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.
  • S Offline
    S Offline
    sixeight
    wrote on last edited by
    #1

    Why do I get a linker error on the following code:

    custompatchlistwidget.h:

    #ifndef CUSTOMPATCHLISTWIDGET_H
    #define CUSTOMPATCHLISTWIDGET_H
    
    #include <QListWidget>
    
    class customPatchListWidget : public QListWidget
    {
    public:
        customPatchListWidget(QWidget *parent);
    
    signals:
        void dragMovePatch(int sourceRow, int destRow);
    
    protected:
        void dragEnterEvent(QDragEnterEvent *event);
        void dropEvent(QDropEvent *event);
    };
    
    #endif // CUSTOMPATCHLISTWIDGET_H
    

    custompatchlistwidget.ccp:

    #include "custompatchlistwidget.h"
    
    #include <QDebug>
    #include <QDragEnterEvent>
    #include <QDragLeaveEvent>
    #include <QDragMoveEvent>
    
    customPatchListWidget::customPatchListWidget(QWidget *parent) : QListWidget(parent)
    {
        Q_UNUSED(parent);
    
        setDragDropMode(QAbstractItemView::InternalMove);
        setDefaultDropAction(Qt::MoveAction);
    }
    
    void customPatchListWidget::dragEnterEvent ( QDragEnterEvent *event )
    {
        if ( event->source() != this ) {
            setDragDropMode ( QAbstractItemView:: DragDrop );
                   event->accept();
        } else {
            setDragDropMode ( QAbstractItemView::InternalMove );
            event->accept();
        }
    
    }
    
    void customPatchListWidget::dropEvent(QDropEvent *event)
    {
        customPatchListWidget *source = (customPatchListWidget*) event->source();
    
        int sourceRow = source->currentRow();
    
        if (event->source() == this) {
            event->acceptProposedAction();
            emit dragMovePatch(sourceRow, currentRow());
        }
    }
    

    If I comment out the emit line, the code compiles fine. I have done exactly the same in a different custom listwidget which compiles fine. But this one will not work. I am at a loss...

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

      @sixeight said in Linking error compiling customListWidget on emitting signal:

      Why do I get a linker error

      You did not post which error you get. Since you want to emit a signal, you have to add Q_OBJECT to your class.

      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
      3
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        As @Christian-Ehrlicher already said Q_OBJECT is missing in the private section of your class. Please as programmer you are declaring the signal. Signals are implemented. Since Q_OBJECT macro is missing, your signal implementation is not there. Hence you are facing the issue.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        1

        • Login

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