Results 1 to 9 of 9

Thread: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

  1. #1
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    Greetings, everyone.

    Here is my problem: I use Qt-4.8.5 (I need that version for work, another versions aren't compatible with my goals). In process of learning QEvents i added some code (functions that override virtual event handling functions and includings of event headers) into some of my classes inherited from QWidget, but deleted that added code later. Since that time when i trying to make new class that inherits QWidget (even in absolutely new projects and in classes that already exist in old projects), compiler says something like that:
    Qt Code:
    1. (.rodata._ZTV10MainWindow[vtable for MainWindow]+0xc8):-1: error: undefined reference to `QWidget::event(QKeyEvent*)'
    2. :-1: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    even if there is no usage of any kind of events in project (I experimented with QKeyEvents too).

    Here is an example of simpliest project that has been created during attempts to find out true source of problem (if additional information is necessary then I ready to provide it, but at the moment I can't even imagine what kind information is necessary in addition to that one):

    PRO-file (generated by Qt Creator):
    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = untitled1
    6. TEMPLATE = app
    7.  
    8.  
    9. SOURCES += main.cpp\
    10. mainwindow.cpp
    11.  
    12. HEADERS += mainwindow.h
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QWidget>
    5.  
    6. #include <QHBoxLayout>
    7. #include <QLabel>
    8.  
    9. class MainWindow : public QWidget
    10. {
    11. Q_OBJECT
    12. //protected:
    13. // virtual void event(QKeyEvent *)
    14. // {
    15. // }
    16. public:
    17. explicit MainWindow(QWidget *parent = 0);
    18. };
    19. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    By the way, if function
    Qt Code:
    1. virtual void event(QKeyEvent *)
    To copy to clipboard, switch view to plain text mode 
    in mainwindow.h is uncommented then everithyng compiles normally and works fine.

    mainwindow.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Cleaning projects and rebuilding them haven't helped to solve this problem so as manual removing of folder with builded project (I use Qt-creator, but with only qmake and make commands problem still appears)
    But standard Qt classes, inherited from QWidget (QDialog, QMainWindow etc) and QWidget itself work normally (I mean, if project has not custom classes inherited from QWidget then everything works fine). For finding true source of problem I tried to compile it with Qt-4.8.6, and this mistake did not appear (but I can't use 4.8.6 permanently)

    It is curious, but there were no compile errors for another QWidget::event() functions and any functions of QWidget or other class.

    Additional information:

    Platform: Linux Red Hat Enterprise Edition 64-bit
    Compiler version: gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4) 64-bit
    Qt and QMake version: Qt-4.8.5
    Qt Creator version: 2.7.2

    The question is: what can cause this problem ( and what could I break, because everithyng used to work fine before ) and what should I try to get rid of it assuming that I have no ability to reinstall Qt and Qt-creator (it is not my own computer)?

    Thanks in advance for any help.
    Last edited by Toniy; 9th July 2015 at 15:54.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    There is no
    Qt Code:
    1. event(QKeyEvent*)
    To copy to clipboard, switch view to plain text mode 
    method.
    There is
    Qt Code:
    1. event(QEvent*)
    To copy to clipboard, switch view to plain text mode 
    though.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    Quote Originally Posted by anda_skoa View Post
    There is no
    Qt Code:
    1. event(QKeyEvent*)
    To copy to clipboard, switch view to plain text mode 
    method.
    There is
    Qt Code:
    1. event(QEvent*)
    To copy to clipboard, switch view to plain text mode 
    though.

    Cheers,
    _
    I checked that in Qt includes. Strange, but I'm watching on it:

    File qwidget.h:
    Qt Code:
    1. #ifndef QWIDGET_H
    2. #define QWIDGET_H
    3. ...
    4. class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
    5. {
    6. ...
    7.  
    8. protected:
    9. // Event handlers
    10. ...
    11. virtual void event(QKeyEvent *);
    12. ...
    To copy to clipboard, switch view to plain text mode 

    What is it then? I mean, it used to be found by compiler before. No changes in Qt original files were made (at least not planned and not manually).
    In any case, why does it try to find it if that stuff is not there or why can't it find it from custom class?

    Cheers
    --
    Last edited by Toniy; 9th July 2015 at 17:20.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    Nope, no such method:

    Qt Code:
    1. #> grep QKeyEvent /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qwidget.h
    2.  
    3. class QKeyEvent;
    4. virtual void keyPressEvent(QKeyEvent *);
    5. virtual void keyReleaseEvent(QKeyEvent *);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #> grep QKeyEvent /usr/include/qt4/QtGui/qwidget.h
    2.  
    3. class QKeyEvent;
    4. virtual void keyPressEvent(QKeyEvent *);
    5. virtual void keyReleaseEvent(QKeyEvent *);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Toniy (9th July 2015)

  6. #5
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    Strange... But how are these differences between yours and mine possible?
    Anyway, thanks: situation is more clear now...

    And how should I act in this situation? Would it be wise to comment these lines in my header or patching third parties' files is bad practicing? If that is so, what can be done?
    However, why does compiler not cry about it for native classes like QWidget? And how could these functions appear into file?
    Last edited by Toniy; 9th July 2015 at 18:24.

  7. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    No virtual void event(QKeyEvent *) either in my mac Qt 5.5.0 installation either:

    Qt Code:
    1. imac01:~/Qt/5.5.0$ grep QKeyEvent /Users/jefft/Qt/5.5.0/clang_64/lib/QtWidgets.framework/Versions/5/Headers/qwidget.h
    2. class QKeyEvent;
    3. virtual void keyPressEvent(QKeyEvent *);
    4. virtual void keyReleaseEvent(QKeyEvent *);
    To copy to clipboard, switch view to plain text mode 
    Seems something is wonky with your Qt installation. If you can't remove/install the Qt packages that installed into /usr, can you perhaps install 4.8.5 into your home directory and see if it matches what you have installed into /usr?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  8. The following user says thank you to jefftee for this useful post:

    Toniy (13th July 2015)

  9. #7
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    All right. I have collected some statistics on different Qt versions and there is no any of these functions. How they appeared and more important how they used to work before -- here is the question.
    I'll reply here when I find source sample that was used for Qt installation on my computer and check it.

    Thanks for the quickest responses.

  10. #8
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    I didn't find sources but deleted that function and replaced it with ones recommended in that thread (in file "qwidget.h") and problem has been solved.
    Seems like I accidentally corrupted that file myself.

    So, maybe that thread will be useful for someone and he/she will solve similar problem quicker

  11. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Undefined reference to QWidget::event(QKeyEvent *) in custom classes

    Seems like I accidentally corrupted that file myself.
    If I were you, I would re-install Qt instead of relying on your memory and hand-editing a really core Qt header file. Who knows what else you've "accidentally corrupted" that might come back to bite you later?

    You are fortunate that you seem to be using a binary distribution of Qt, and the linker caught your error.

  12. The following user says thank you to d_stranz for this useful post:

    Toniy (20th July 2015)

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 10:51
  2. Replies: 4
    Last Post: 20th July 2012, 12:41
  3. Replies: 1
    Last Post: 3rd February 2011, 16:06
  4. Replies: 3
    Last Post: 4th October 2010, 16:39
  5. Replies: 6
    Last Post: 14th May 2009, 13:02

Tags for this Thread

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.