set text to qlineedit on focus

  • i wanna set text to line edit whenever the focus is on it. i searched online and found out that this is possible in qt5 but not in qt4. but that doesn't matter.

    here's my code:

    class some_class {
        some_class() {
            // some code...
            lineEdit = new QLineEdit; 
            QObject::connect(lineEdit, &QLineEdit::focusInEvent(QFocusEvent *), lineEdit, [this]() {
    protected slots:
        // some slots...
         QLineEdit *lineEdit;
         // other members...

    and here's the error i get for QFocusEvent *event's asterisk :

    error: expected primary-expression before '*' token

    what does this mean?

    by the way, i've also tred this which didn't work either:

    QObject::connect(lineEdit, &QLineEdit::focusInEvent, lineEdit, [this]() {

  • focusInEvent is protected function. You will not be use it like this in lambda. You can subclass QLineEdit and re-implement focusInEvent function to make your use case.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.