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>
{
Q_OBJECT
public:
MyLineEdit();
signals:
void MyKeyUpPressed();
protected:
};
#endif // MYLINEEDIT_H
#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
To copy to clipboard, switch view to plain text mode
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:
break;
}
}
#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;
}
}
To copy to clipboard, switch view to plain text mode
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";
//}
//void MyLineEdit::MyKeyUpPressed()
//{
//qDebug() << "Key up";
//}
To copy to clipboard, switch view to plain text mode
Bookmarks