0

我想在 lineedit1 失去焦点后做一些具体的事情。这是应用程序的代码片段:

QFocusEvent* focuslost = new QFocusEvent(QEvent::FocusOut);
void lineedit1::focusOutEvent(focuslost) {
  //do something
}

但它给了我编译器错误:

错误:名称后跟“::”必须是类或命名空间名称

我该怎么做才能实现这样的功能?

4

1 回答 1

1

您不能只覆盖对象实例上的方法,您需要创建一个继承QLineEdit并覆盖该方法的新类focusOutEvent

mylineedit.h

class MyLineEdit : public QLineEdit
{
protected:
    void focusOutEvent(QFocusEvent * e) override;
}

mylineedit.cpp

void MyLineEdit::focusOutEvent(QFocusEvent * e)
{
    // your code here

    QLineEdit::focusOutEvent(e);
}

然后声明lineedit1MyLineEdit* lineedit1

于 2013-07-19T11:28:04.423 回答