I read the documentation on QDataWidgetMapper and I think this has way more functionality than what I need. I think the QComboBox::addItem is the way to go but I am not quite there. I am not sure how to get the data with QComboBox::itemData(). Here is what I have.
while (riderquery.next())
{
ui->cmbRider->addItem(riderquery.value (2).toString()+ " "+ riderquery.value (1).toString(),riderquery.value (0).toInt()); //populates combobox with name and id Is this the correct syntax?
}
}
while (riderquery.next())
{
ui->cmbRider->addItem(riderquery.value (2).toString()+ " "+ riderquery.value (1).toString(),riderquery.value (0).toInt()); //populates combobox with name and id Is this the correct syntax?
}
}
To copy to clipboard, switch view to plain text mode
void MainWindow::on_cmbRider_currentIndexChanged(int index)
{
Sqlstring="SELECT id, LName, FName, weight, notes * FROM rider WHERE id=" + ui->cmbRider->itemData(0).toString(); //This is where I think I have a problem. I think it is with the ui->cmbRider->itemData(0).toString()
query.prepare(Sqlstring);
query.exec();
ui->txtFName->text().clear();
ui->txtFName->text()=(query.value (1)); //this should populate the lineedit box with the new data
}
void MainWindow::on_cmbRider_currentIndexChanged(int index)
{
QString Sqlstring;
QSqlQuery query ;
Sqlstring="SELECT id, LName, FName, weight, notes * FROM rider WHERE id=" + ui->cmbRider->itemData(0).toString(); //This is where I think I have a problem. I think it is with the ui->cmbRider->itemData(0).toString()
query.prepare(Sqlstring);
query.exec();
ui->txtFName->text().clear();
ui->txtFName->text()=(query.value (1)); //this should populate the lineedit box with the new data
}
To copy to clipboard, switch view to plain text mode
I get several errors related to this: no match for 'operator=' in 'QLineEdit::text() const() =QSqlquery::value() const()'
what am I missing?
PS. Is there a post or some documentation on how to decipher the classes? Like exactly what does void QComboBox::insertItem ( int index, const QString & text, const QVariant & userData = QVariant() ) mean and how do you use it? I get some of the basics, but not sure how to intrepret it entirely. The explanation of this might help me understand future problems.
I really appreciate all the help!
Bookmarks