Qt - I want to use the QComboBox after the return/enter is pressed.
-
@jsulm don't know. I tried to use
QLineEdit::editingFinished()
in my connect function like:
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
-
@jsulm don't know. I tried to use
QLineEdit::editingFinished()
in my connect function like:
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
hi
should that not be
connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath); -
@jsulm don't know. I tried to use
QLineEdit::editingFinished()
in my connect function like:
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
@developer_96 said in Qt - I want to use the QComboBox after the return/enter is pressed.:
but it does not work
As mentioned already: you need to get the pointer to the line edit using QLineEdit *QComboBox::lineEdit() and use that pointer in the connect.
-
@jsulm don't know. I tried to use
QLineEdit::editingFinished()
in my connect function like:
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
I guess you'll need to pick up
QLineEdit *QComboBox::lineEdit()
and slot ontoQLineEdit::editingFinished()
for that. -
@developer_96
You have aQComboBox
. I gave you the method you need to access itsQLineEdit
.connect()
the line edit'sQLineEdit::editingFinished
signal to the desired slot. -
@JonB i try to acces it by using
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
and
connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
Thank you for the help. -
@JonB i try to acces it by using
connect(ui.leftBox, &QLineEdit::editingFinished, this, &MainCom::updatepath);
and
connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
but it does not work.
Thank you for the help.@developer_96
The first one will generate a compiler-time error.The second one is correct. What "does not work"? have you tried putting a
qDebug()
in your&MainCom::updatepath()
method, does it get hit? -
@JonB it says "An incomplete type is not allowed" for &QLineEdit::editingFinished.
-
@JonB it says "An incomplete type is not allowed" for &QLineEdit::editingFinished.
@developer_96
Put#include <QLineEdit>
at the head of your source (.cpp
) file. -
@JonB thank you. yeah i know but i removed it cause i get this problem after i put in and try to debug:
-
@JonB thank you. yeah i know but i removed it cause i get this problem after i put in and try to debug:
@developer_96 Please show the relevant code.
Does your updatepath() slot have any parameters? -
@jsulm
Connect:connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
Updaatepath:
void MainCom::updatepath(const QString& path)
-
And where do you expect does
const QString& path
should come from when the signal does not have a parameter? -
@jsulm
Connect:connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
Updaatepath:
void MainCom::updatepath(const QString& path)
@developer_96 said in Qt - I want to use the QComboBox after the return/enter is pressed.:
QLineEdit::editingFinished
Has no parameter, so you can't connect it with a slot which expects a parameter. That's exactly what the first error message is saying.
-
@jsulm
Connect:connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, &MainCom::updatepath);
Updaatepath:
void MainCom::updatepath(const QString& path)
@developer_96
One/the best way of doing what you want --- pass your own extra parameter to slot --- is to learn to use C++ lambdas here:connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, [this]() { this->updatepath(this->ui.leftBox->lineEdit()->text()); }); // or next line does exactly the same thing, depends which you find clearer connect(ui.leftBox->lineEdit(), &QLineEdit::editingFinished, this, [this]() { updatepath(ui.leftBox->lineEdit()->text()); });
-
@JonB @Christian-Ehrlicher @jsulm thank you very much for the answers. I did it now. The function will be called after i type "return". But now if i chose one of the drop & down the programm wants from to type "return" again. My Idea was to type "return" when i manually type a path. When i'm going to select one path of the drop & down i want to update it immediately.
Regards
-
@JonB @Christian-Ehrlicher @jsulm thank you very much for the answers. I did it now. The function will be called after i type "return". But now if i chose one of the drop & down the programm wants from to type "return" again. My Idea was to type "return" when i manually type a path. When i'm going to select one path of the drop & down i want to update it immediately.
Regards
@developer_96
So far you have dealt with the user editing the text. For choosing an item from the dropdown, I think you have to also connect theQComboBox::currentIndexChanged()
to your slot.P.S.
It's not your fault thatQComboBox
does not seem to define one signal for "finished editing, either by typing all into the line edit or selecting an item from the dropdown". It would have been nicer if it did. -
@JonB so its possible to connect two signals to one slot?
-
@JonB so its possible to connect two signals to one slot?
@developer_96
Absolutely! Many-to-many relationship: as many signals as you like connected to same slot and/or as many slots as you like connected to any signal.