PDA

View Full Version : MyLineEdit + signals lead to multiple definition [solved]



schotter
4th February 2015, 12:23
Great, no I fucked my posting up...

I try to rewrite it again. All I wanted was a LineEdit that emits signals if e.g. Qt::Key_Up was pressed. Therefore I subclassed QLineEdit as the following code shows.


#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H

#include <QLineEdit>
#include <QKeyEvent>

class MyLineEdit : public QLineEdit
{
Q_OBJECT

public:
MyLineEdit();

signals:
void MyKeyUpPressed();

protected:
void keyPressEvent(QKeyEvent *event);
};

#endif // MYLINEEDIT_H


First I only had qDebug() within keyPressEvent() and everything compiled :) Then I added MyKeyUpPressed() as a signal, as it's shown in the code.


#include "mylineedit.h"
#include <QDebug>

MyLineEdit::MyLineEdit()
{
}

void MyLineEdit::MyKeyUpPressed()
{
qDebug() << "Key up";
}

void MyLineEdit::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Up:
emit MyLineEdit::MyKeyUpPressed();
// qDebug() << "Key Up";
break;
default:
QLineEdit::keyPressEvent(event);
break;
}
}


At that point I got compiling errors...

(..)\debug\moc_mylineedit.cpp:121: Fehler: multiple definition of `MyLineEdit::MyKeyUpPressed()'

Any Suggestions?

----------------------------------------------------------------

What an easy, dumb failure.....There is no need to fill signals with life (code).


//void MyLineEdit::MyKeyUpPressed()
//{
//qDebug() << "Key up";
//}