Results 1 to 11 of 11

Thread: event handler

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default event handler

    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
    Qt Code:
    1. #include <QtGui/QWidget>
    2. #include "ui_event.h"
    3.  
    4. class event : public QWidget
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. event(QWidget *parent = 0);
    10. ~event();
    11. protected:
    12. void keyEvent(QKeyEvent *event);
    13. private:
    14. Ui::eventClass ui;
    15. };
    To copy to clipboard, switch view to plain text mode 

    event.cpp
    Qt Code:
    1. #include <QtGui/QWidget>
    2. #include "event.h"
    3.  
    4. event::event(QWidget *parent)
    5. : QWidget(parent)
    6. {
    7. ui.setupUi(this);
    8. }
    9.  
    10. event::~event()
    11. {
    12.  
    13. }
    14.  
    15. void event::keyEvent(QKeyEvent *event)
    16. {
    17. //event->key(); --> error: invalid use of undefined type 'struct QKeyEvent', why?
    18. ui.label->setText("Yeah!");
    19. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event handler

    i have to reimplement keyPressEvent not keyEvent...now the thext changes, but I still have the error when i use event->key()

  3. #3
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event handler

    error: invalid use of undefined type 'struct QKeyEvent':
    The compiler has no idea about the data type QKeyEvent.

    You most likely miss an include.

  4. The following user says thank you to DeepDiver for this useful post:

    mattia (8th November 2007)

  5. #4
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event handler

    for example this #include <QKeyEvent>. thanks

  6. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event handler

    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 that QLineEdit can emit textChanged ( const QString & text ) signal so i made a connection to hook it in ths way:
    Qt Code:
    1. connect(ui.lineEditExpression, SIGNAL(QLineEdit::textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
    To copy to clipboard, switch view to plain text mode 
    where lineEditExpression is a pointer to QLineEdit, but when application start i see a warning like this:
    Qt Code:
    1. Object::connect: No such signal QLineEdit::QLineEdit::textChanged(QString)
    2. Object::connect: (sender name: 'lineEditExpression')
    3. Object::connect: (receiver name: 'regExpClass')
    To copy to clipboard, switch view to plain text mode 
    to complite i post all my class code:
    Qt Code:
    1. #include "QRegExp"
    2. #include "QRegExpValidator"
    3. #include <QLineEdit>
    4. #include "regexp.h"
    5.  
    6. regExp::regExp(QWidget *parent)
    7. : QWidget(parent)
    8. {
    9. ui.setupUi(this);
    10. connect(ui.pushButtonClose, SIGNAL(clicked()), this, SLOT(close()));
    11. connect(ui.pushButtonValidate, SIGNAL(clicked()), this, SLOT(validator()));
    12. connect(ui.lineEditExpression, SIGNAL(QLineEdit::textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
    13. }
    14.  
    15. regExp::~regExp()
    16. {
    17.  
    18. }
    19.  
    20. void regExp::validator()
    21. {
    22. stringExpression = ui.lineEditExpression->text();
    23. stringValidator = ui.lineEditRE->text();
    24.  
    25. QRegExp re(stringValidator);
    26. int result = re.indexIn(stringExpression);
    27. ui.labelOut->setText(QString::number(result, 10));
    28. }
    29.  
    30. void regExp::emptyLine(const QString &text)
    31. {
    32. ui.labelOut->setText("changed");
    33. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: event handler

    Drop the extra QLineEdit::
    Qt Code:
    1. connect(ui.lineEditExpression, SIGNAL(textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #7
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event handler

    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) ????

  9. #8
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event handler

    Quote Originally Posted by jpn View Post
    Drop the extra QLineEdit::
    Qt Code:
    1. connect(ui.lineEditExpression, SIGNAL(textChanged(const QString &)), this, SLOT(emptyLine(const QString &)));
    To copy to clipboard, switch view to plain text mode 
    you are always faster than me

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: event handler

    Quote Originally Posted by DeepDiver View Post
    you are always faster than me
    Not always... Btw, have you noticed that you can see if others have posted meanwhile writing your post by previewing it?
    J-P Nurmi

  11. #10
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event handler

    Quote Originally Posted by jpn View Post
    Btw, have you noticed that you can see if others have posted meanwhile writing your post by previewing it?
    Hmmm ... - - No - give me a hint!

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: event handler

    Quote Originally Posted by DeepDiver View Post
    Hmmm ... - - No - give me a hint!
    Hit the "Preview Post" button: http://www.qtcentre.org/forum/f-feed...time-2336.html
    J-P Nurmi

  13. The following user says thank you to jpn for this useful post:

    mattia (8th November 2007)

Similar Threads

  1. QDockWidget-title
    By moowy in forum Qt Programming
    Replies: 18
    Last Post: 23rd April 2014, 21:13
  2. Replies: 1
    Last Post: 16th October 2007, 23:41
  3. Create new an event, help me?
    By dungsivn in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 12:22
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 10:05
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 22:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.