阅读背景:

关于错误: error: variable ‘QApplication app’ has initializer but incomplete type

来源:互联网 
#include <QApplication>
#include <QMainWindow>
#include <QTextEdit>
#include <QKeyEvent>
#include <QDebug>

class MainWindow : public QMainWindow
 {
 public:
     MainWindow();

 protected:
     bool eventFilter(QObject *obj, QEvent *ev);

 private:
     QTextEdit *textEdit;
 };

 MainWindow::MainWindow()
 {
     textEdit = new QTextEdit;
     setCentralWidget(textEdit);

     textEdit->installEventFilter(this);
 }

 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
 {
     if (obj == textEdit) {
         if (event->type() == QEvent::KeyPress) {
             QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
             qDebug() << "Ate key press" << keyEvent->key();
             return true;
         } else {
             return false;
         }
     } else {
         // pass the event on to the parent class
         return QMainWindow::eventFilter(obj, event);
     }
 }

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     app.setOrganizationName("c-cube");
     app.setApplicationName("Evt filter Example");
     MainWindow mainWin;
     mainWin.show();
     return app.exec();
}
#include <QApplication>
#include <QMainWindow>



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: