Unsolved Linking error compiling customListWidget on emitting signal
-
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...
-
@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.
-
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.