0

I want to do specific things after focus is lost on lineedit1. Here is the code piece from the application:

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

but it gives me compiler error:

error: name followed by "::" must be a class or namespace name

What can I do to implement such a function?

1 Answer 1

1

You cannot just override a method on an instance of an object, you need to create a new class that inherits from QLineEdit and overrides the method 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); } 

Then declare lineedit1 as MyLineEdit* lineedit1

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.