Results 1 to 9 of 9

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 14:54.

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. Replies: 4
    Last Post: 20th July 2012, 11:41
  3. Replies: 1
    Last Post: 3rd February 2011, 15:06
  4. Replies: 3
    Last Post: 4th October 2010, 15:39
  5. Replies: 6
    Last Post: 14th May 2009, 12: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.