Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. set text to qlineedit on focus

set text to qlineedit on focus

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    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 {
    
        Q_OBJECT
    
    public:
        some_class() {
    
            // some code...
    
            lineEdit = new QLineEdit; 
            QObject::connect(lineEdit, &QLineEdit::focusInEvent(QFocusEvent *), lineEdit, [this]() {
                lineEdit->setText("some_text");
            });
        }
    
    protected slots:
        // some slots...
    
    private:
         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]() {
        lineEdit->setText("some_text");
    });
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved