PDA

View Full Version : ComboBox with QSqlTableModel



musti
9th November 2007, 15:23
I filled combobox with model like this
cityModel = new QSqlTableModel(this);
cityModel->setTable("cities"); // (city_id, city_name)
cityModel->select();
comboBox_city->setModel(cityModel);
comboBox_city->setModelColumn(1);
comboBox_city->setCurrentIndex(0);

I can get current city_id with currentIndexChanged signal.
How can i get city_id from comboBox any time without signal?

jpn
9th November 2007, 20:30
May I ask how did you find out QComboBox::currentIndexChanged()? From docs? There is also QComboBox::currentIndex() and QComboBox::setCurrentIndex().. :)

int idx = comboBox_city->currentIndex();

mkarakaplan
10th November 2007, 00:22
I didn't find from docs. It is too complex just for me now. I asked here in the newbie forum and someone helped me.
I am just trying to make a real application from QtDemos with model->copyPaste for now.
I developed this solution. It took my two hours.

QVariant city_id = cityModel->data(cityModel->index(comboBox_City->currentIndex(),0) );

jpn
10th November 2007, 00:49
No worries, luckily the documentation of Qt is great! :) A special application, Qt Assistant (http://doc.trolltech.com/4.3/assistant-manual.html) is provided together with Qt. The "index" tab of Qt Assistant is awesome. Just try to write for example "currentIndex" into index-tab and you'll see. Oh, and the same documentation also available online (http://doc.trolltech.com/4.3/).