QPushButton *button = new QPushButton("Click me", parent); button->setFocus();
QLineEdit *lineEdit = new QLineEdit(parent); lineEdit->setFocusPolicy(Qt::StrongFocus); lineEdit->setFocus();In this example, a new QLineEdit object is created with the parent widget as its parent. The setFocusPolicy() function is called to set the focus policy to the StrongFocus policy. Finally, the setFocus() method is called to set the focus to this widget. Both of these examples use the Qt library package for their implementation.