PDA

View Full Version : currentText in Qcombobox



Vidhya
23rd July 2012, 07:42
How can i get the current text of Qcombobox in QtableWidget

Charvi
23rd July 2012, 07:45
use the combobox.currentText() method.

Vidhya
23rd July 2012, 08:02
it is not working because it is in the QtableWidget

Charvi
23rd July 2012, 08:04
can u post the code snippet in question ?

Vidhya
25th July 2012, 06:36
int row=1;
int col=8;
QComboBox *com=new QComboBox(this);
com->addItems(dislist);
ui->widget->setCellWidget(row,col,com);


Note:

ui->widget - is QtableWidget,
then how can i get the currentText in the Qcombobox

Pls help me

Thank U

ChrisW67
25th July 2012, 06:55
Exactly the same way you do anywhere else, by using a pointer to the control:


com->currentText();

You have to keep a pointer to the control to be able to do this.

Ginsengelf
25th July 2012, 06:59
Or (if you know what you are doing) you can use QTableWidget::cellWidget(), cast it to QComboBox and then use currentText(). But this may cause disaster when used incorrectly...

Ginsengelf

Vidhya
25th July 2012, 07:28
i want to get the text of combobox in another function.
can u pls explain me.
How to code this

Santosh Reddy
25th July 2012, 07:42
Check this out



int row = 1;
int col = 8;
QStringList dislist;
QComboBox* com = new QComboBox(this);
com->addItems(dislist);
ui->widget->setCellWidget(row, col, com);

//another function
QComboBox* cell_com = dynamic_cast<QComboBox*>(ui->widget->cellWidget(1, 8));
QString text;
if(cell_com != 0)
{
text = cell_com->currentText();
}

Vidhya
25th July 2012, 07:57
its working !
Thank U, Thank U,Thank U very much......