zuberek
22nd February 2012, 07:38
Hello!
First of all, Im new here, so I just want to say Hi to everybody ;)
Ok, here is my problem.
Look at this code:
QSqlQueryModel *modelClientsList = new QSqlQueryModel;
modelClientsList->setQuery("SELECT client_id, client_fullName, client_city, client_street, client_code, client_nip, client_regon, client_contactName, client_phone, client_fax, client_url, client_email, client_notes FROM scm_clients");
modelClientsList->setHeaderData(0, Qt::Horizontal, QObject::trUtf8("ID"));
modelClientsList->setHeaderData(1, Qt::Horizontal, QObject::trUtf8("Name"));
modelClientsList->setHeaderData(2, Qt::Horizontal, QObject::trUtf8("City"));
AND
ui->clientComboBox->setModel(modelClientsList);
ui->clientComboBox->setModelColumn(1);
ui->clientComboBox->setCurrentIndex(-1);
AND
void StackedWidget::on_clientComboBox_currentIndexChang ed(int index)
{
qDebug() << ui->clientComboBox->itemData(index);
qDebug() << ui->clientComboBox->itemData(currentIndex()).toString();
}
What I want to do is when I choose something from comboBox it should automatically put values (i.e. client_fullName, client_city, client_street ...) into lineEdit positions.
And here is the question: How can I get other values set by model from comboBox?
Second thing is, I use the very same model for displaying data in QTableView and it works fine. I use QStackedWidget for displaying whole stuff. I have a "new invoice" button next to the QTableView. Question: How to set QComboBox position to be the same as selected position from QTableView?
I tried to pass var CurrentClientId (which is client_id from database), but QComboBox provides default autoincrement values for positions in combobox. So CurrentClientId from QTableView is not the same as currentIndex() from QComboBox.
I hope I've explained everything clearly and You can understand what my problem is :-)
EDIT:
Q1: I guess I can make it work by adding items one by one in while(...) loop using addItem(name, id) and then querying each position separately, but it doesn't feels right. Any hint?
Thanks for any help!
Cheers!
First of all, Im new here, so I just want to say Hi to everybody ;)
Ok, here is my problem.
Look at this code:
QSqlQueryModel *modelClientsList = new QSqlQueryModel;
modelClientsList->setQuery("SELECT client_id, client_fullName, client_city, client_street, client_code, client_nip, client_regon, client_contactName, client_phone, client_fax, client_url, client_email, client_notes FROM scm_clients");
modelClientsList->setHeaderData(0, Qt::Horizontal, QObject::trUtf8("ID"));
modelClientsList->setHeaderData(1, Qt::Horizontal, QObject::trUtf8("Name"));
modelClientsList->setHeaderData(2, Qt::Horizontal, QObject::trUtf8("City"));
AND
ui->clientComboBox->setModel(modelClientsList);
ui->clientComboBox->setModelColumn(1);
ui->clientComboBox->setCurrentIndex(-1);
AND
void StackedWidget::on_clientComboBox_currentIndexChang ed(int index)
{
qDebug() << ui->clientComboBox->itemData(index);
qDebug() << ui->clientComboBox->itemData(currentIndex()).toString();
}
What I want to do is when I choose something from comboBox it should automatically put values (i.e. client_fullName, client_city, client_street ...) into lineEdit positions.
And here is the question: How can I get other values set by model from comboBox?
Second thing is, I use the very same model for displaying data in QTableView and it works fine. I use QStackedWidget for displaying whole stuff. I have a "new invoice" button next to the QTableView. Question: How to set QComboBox position to be the same as selected position from QTableView?
I tried to pass var CurrentClientId (which is client_id from database), but QComboBox provides default autoincrement values for positions in combobox. So CurrentClientId from QTableView is not the same as currentIndex() from QComboBox.
I hope I've explained everything clearly and You can understand what my problem is :-)
EDIT:
Q1: I guess I can make it work by adding items one by one in while(...) loop using addItem(name, id) and then querying each position separately, but it doesn't feels right. Any hint?
Thanks for any help!
Cheers!