Solved Problem with dialog child
-
this happens when only one return in line edit is pressed:
![alt text]( image url) -
I try another way with the same result:
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); QObject::connect(ui->lineEdit,&QLineEdit::returnPressed,this,&Dialog::onReturnPressed); QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Dialog::onReturnPressed); } Dialog::~Dialog() { delete ui; } void Dialog::onReturnPressed() { qDebug()<< "test dialog "; qDebug()<< "dsdas"; }
it seems there is a problem between signal click() and clicked()
-
It's normal, a dialog has a defaut button, when pressing enter, the defaut button emits the clicked signal.
see: default button
-
Can you share the declarations (.h) of your classes?
In the while, can you try to develop this project without using the Design to see what happens?
-
Hi
I agree with @mpergand and also thinks its the dialog helping.Pressing enter in line edits triggers this
QObject::connect(ui->lineEdit,&QLineEdit::returnPressed,this,&Dialog::onReturnPressed);
However, the lineedit do not eat the enter. its send to button.
the button is "default" (when created with Designer at least) meaning pressing enter
trigger it and it emits
QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Dialog::onReturnPressed); -
I don't understand what the problem here is.
There are two separate signals going on here.
-
You have clicked RETURN in a
QLineEdit
, and you have chosen to catch that signal. -
Since
QLineEdit
, unlikeQTextEdit
, is single-line, it does not accept RETURN. So it passes it on to theQDialog
to handle. Which (as @mpergand said) has a default button, which is invoked when RETURN is pressed. That only happens in a dialog, not a window.
What is the issue? The obvious question is why you are interested in handling
QLineEdit::returnPressed()
signal at all? -
-
you're all right sorry for ignorance,
i'm intrested in QLineEdit::returnPressed because with this dialog a user could insert more than 1 record in database and he could do it with returnPressed from QLineEdit.
i think i should do it in another way :D -
@Pantof
Nothing to be sorry for!i'm intrested in QLineEdit::returnPressed because with this dialog a user could insert more than 1 record in database and he could do it with returnPressed from QLineEdit.
What do you mean by this?
It sounds a little odd, but if you have a legitimate reason it may be that the better solution is to prevent that RETURN from causing the default dialog action. The principle
QDialog
is working on is that a RETURN --- unless it is intended for the current widget --- is aimed at the dialog. That sounds like it may not correspond to what you are intending. -
@JonB
normally the application show show a table from database when you click a pushbutton you open a Form (done with qDialog) that give you the possibility to insert new records. to speed up this job i use the return pressed from qLineEdit so you shouldn't move out to grab the mouse.
actually i switch to qWidget. -
i use the return pressed from qLineEdit
If you choose to do that, I would think you need to not let that key/return press to do it's normal action of activating the dialog's default button action. Such as, you could use event filter on the dialog perhaps. Or, I imagine a
QDialog
can be told not to have a default button/return press.