Results 1 to 2 of 2

Thread: warning: invalid use of incomplete type 'class QEvent'

  1. #1
    Join Date
    Oct 2016
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Smile warning: invalid use of incomplete type 'class QEvent'

    I got this warning when I compile the following code:
    //MainWindow.h
    Qt Code:
    1. #include <QPushButton>
    2. #include "mywidget.h"
    3.  
    4. class MainWindow : public QMainWindow
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. MainWindow(QWidget *parent = 0);
    10. ~MainWindow();
    11. protected:
    12. bool eventFilter(QObject *obj, QEvent *e);
    13. private:
    14. QPushButton *button;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 
    //MainWindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. button = new QPushButton;
    5. this->setCentralWidget(button);
    6. button->installEventFilter(button );
    7. }
    8.  
    9. MainWindow::~MainWindow()
    10. {
    11. }
    12.  
    13. bool MainWindow::eventFilter(QObject *obj,QEvent *e)
    14. {
    15. if (obj == button)
    16. {
    17. if (e->type() == QEvent::MouseButtonPress) // this is the statement warning happened.
    18. {
    19. QMouseEvent *event = static_cast<QMouseEvent*> (e);
    20. button->setText(QString("Press: %1, %2").arg(QString::number(event->x()), QString::number(event->y())));
    21. return true;
    22. }
    23. ...
    24. }
    To copy to clipboard, switch view to plain text mode 
    Anybody can help me to find the reason?
    Last edited by anda_skoa; 11th October 2016 at 18:48. Reason: missing [code] tags

  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: warning: invalid use of incomplete type 'class QEvent'

    That kind of error indicates a missing include.
    In your case the include for QMouseEvent.

    Cheers,
    _

Similar Threads

  1. invalid use of incomplete type 'struct MSG'
    By libed in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2019, 12:32
  2. invalid use of incomplete type 'class QWebFrame'
    By rahulvishwakarma in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2016, 16:46
  3. Replies: 2
    Last Post: 13th October 2012, 16:58
  4. Replies: 9
    Last Post: 29th August 2010, 14:30
  5. error: invalid use of incomplete type 'struct QMetaEnum'
    By dyngoman in forum Qt Programming
    Replies: 3
    Last Post: 12th March 2010, 13:38

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.