PDA

View Full Version : event handler



mattia
8th November 2007, 08:37
Hello, i was trying to reimplementing QKeyEvent event handler but i get some trouble, when i press any keys nothing happen and if i try to use event->key() i get another error.
Down here the code.

event.h

#include <QtGui/QWidget>
#include "ui_event.h"

class event : public QWidget
{
Q_OBJECT

public:
event(QWidget *parent = 0);
~event();
protected:
void keyEvent(QKeyEvent *event);
private:
Ui::eventClass ui;
};


event.cpp

#include <QtGui/QWidget>
#include "event.h"

event::event(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}

event::~event()
{

}

void event::keyEvent(QKeyEvent *event)
{
//event->key(); --> error: invalid use of undefined type 'struct QKeyEvent', why?
ui.label->setText("Yeah!");
}


ui_event is just a widget with a QLabel.
What's wrong?
Thanks

mattia
8th November 2007, 08:40
i have to reimplement keyPressEvent not keyEvent...now the thext changes, but I still have the error when i use event->key()

DeepDiver
8th November 2007, 08:58
error: invalid use of undefined type 'struct QKeyEvent':
The compiler has no idea about the data type QKeyEvent.

You most likely miss an include.

mattia
8th November 2007, 09:08
for example this #include <QKeyEvent>. thanks

mattia
8th November 2007, 11:41
I'm not going to open another thread cos the topic is quite like before, if I should do it please tell me, next time i'll do it.
I saw here (http://doc.trolltech.com/4.2/qlineedit.html#textChanged) that QLineEdit can emit textChanged ( const QString & text ) signal so i made a connection to hook it in ths way:

connect(ui.lineEditExpression, SIGNAL(QLineEdit::textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
where lineEditExpression is a pointer to QLineEdit, but when application start i see a warning like this:

Object::connect: No such signal QLineEdit::QLineEdit::textChanged(QString)
Object::connect: (sender name: 'lineEditExpression')
Object::connect: (receiver name: 'regExpClass')
to complite i post all my class code:

#include "QRegExp"
#include "QRegExpValidator"
#include <QLineEdit>
#include "regexp.h"

regExp::regExp(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButtonClose, SIGNAL(clicked()), this, SLOT(close()));
connect(ui.pushButtonValidate, SIGNAL(clicked()), this, SLOT(validator()));
connect(ui.lineEditExpression, SIGNAL(QLineEdit::textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
}

regExp::~regExp()
{

}

void regExp::validator()
{
stringExpression = ui.lineEditExpression->text();
stringValidator = ui.lineEditRE->text();

QRegExp re(stringValidator);
int result = re.indexIn(stringExpression);
ui.labelOut->setText(QString::number(result, 10));
}

void regExp::emptyLine(const QString &text)
{
ui.labelOut->setText("changed");
}

jpn
8th November 2007, 11:55
Drop the extra QLineEdit::

connect(ui.lineEditExpression, SIGNAL(textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));

DeepDiver
8th November 2007, 11:56
Pretty easy:
Have a look at this:
Object::connect: No such signal QLineEdit::QLineEdit::textChanged(QString)

Is this the correct method signature: QLineEdit::QLineEdit::textChanged(QString) ????

DeepDiver
8th November 2007, 11:56
Drop the extra QLineEdit::

connect(ui.lineEditExpression, SIGNAL(textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));

:o you are always faster than me :o

jpn
8th November 2007, 12:15
:o you are always faster than me :o
Not always... ;) Btw, have you noticed that you can see if others have posted meanwhile writing your post by previewing it?

DeepDiver
8th November 2007, 12:22
Btw, have you noticed that you can see if others have posted meanwhile writing your post by previewing it?

Hmmm ... - :confused: - No - give me a hint!

jpn
8th November 2007, 12:54
Hmmm ... - :confused: - No - give me a hint!
Hit the "Preview Post" button: http://www.qtcentre.org/forum/f-feedback-13/t-two-people-replying-at-the-same-time-2336.html