Qt 重写了QLineEdit的focusInEvent(QFocusEvent *e) ,提示without object错误
需要焦点移入QLineEdit后做些处理,查看了文档说可以重写focusInEvent(QFocusEvent *e)
但是总是会提示cannot call member function 'virtual void QLineEdit::focusInEvent(QFocusEvent*)' without object 错误。
代码非常简单,如下:
.h
#include <QMainWindow>
#include <QFocusEvent>
#include <QLineEdit>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void focusInEvent(QFocusEvent *);
private:
Ui::MainWindow *ui;
};
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qdebug.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::focusInEvent(QFocusEvent *e)
{
QLineEdit::focusInEvent(e);
qDebug()<<"??????????";
}