int main(int ac, char **av)
{
QApplication app(ac, av);
Dialog *dialog = new Dialog();
dialog->show();
return app.exec();
}
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private slots:
void onLineEdit();
void onButtonClicked();
private:
Ui::Dialog *ui;
};
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(ui->lineEdit, SIGNAL(editingFinished()), this, SLOT(onLineEdit()));
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::onLineEdit() {
qDebug() << QString("line edit finish");
}
void Dialog::onButtonClicked() {
qDebug() << QString("button clicked");
}
Above is the demo code, the functionality is very simple, and the interface is as the picture shows. The GUI interface
In this pic, a groupBox wraps the lineEdit & pushButton. When I input some text into the LineEdit, then move the mouse to another place, but within the groupBox, the LineEdit Won't emit the editingfinished() signal.
This situation means the lineEdit doesn't lose focus. This problem is really strange. Could you tell me what's wrong.
Thanks ahead.
Though the documentation of
QLineEdit::editingFinished()
doesn't state it explicitely, focus means in this case keyboard focus, e. g. pressing the Tab key or Enter, but not moving the mouse cursor someplace else without clicking on some other focusable widget.If you want to implement a different behaviour and don't know how you should say so.