Gansroy
Gansroy

Reputation: 229

How to get current QString text from QComBox automatically in c++?

Normally I saw, When QComboBox is being used in Qt user interface, in order to run the program with current QString text from QComboBox, there has to be a QPushButton, by pressing which the program run with the current QString text from QComboBox and thus the current QString text can be obtained. But I want to know if there is any function in QComboBox, which will pass currently changed QString text from QComboBox to the program automatically. I mean, when I change QComboBox current text, the program will automatically run with the action of this particular current text instead of pressing the QPushButton again and again.

It may be a task of very simple function, but surprisingly I am not able to find it out.

I appreciate your help. Thanks in advance.

Upvotes: 3

Views: 860

Answers (2)

saeed
saeed

Reputation: 2497

You can use QComboBox signals like

void currentIndexChanged(int index)
void currentIndexChanged(const QString &text)
void currentTextChanged(const QString &text)
void editTextChanged(const QString &text)

Connect these signals to the proper slot, it automatically notifies slot.

Upvotes: 2

jgorostegui
jgorostegui

Reputation: 1310

Taking a look at the documentation, it is possible to see the available notifier signals for this matter:

void    currentIndexChanged(int index)
void    currentIndexChanged(const QString & text)

Using them you can have your problem solved.

You can use then connect to handle the event:

connect(ui->comboBox, SIGNAL(currentIndexChanged(QString)), SLOT(yourfunction(QString)));

Creating your own yourfunction() or just using Qt Creator interface.

Upvotes: 0

Related Questions