poporacer
6th November 2010, 05:13
I have a couple of issues but I think if I can learn the debug syntax, I might be able to find the issue (and some of my future issues!) I have a combobox that gets populated in a routine. In this routine two fields from a table are loaded (first name and last name). There are lin edit fields to make changes. If the user makes a change to the name, I want the combobox to get populated with the corrected name and then the combobox should display the item that is currently displayed. The combobox goes back to the first index each time. I tried using QDebug and got errors and while searching posts I see that people are using qDebug. What is the difference? I want to post the contents of a variable to see what is going on. What is the syntax for QDebug and qDebug. Here is what I tried and the output did not make sense.
//************************************************** ***********************
//routine to check if data has been changed.
//if it has, give the user the option to save the changes
//************************************************** ***********************
bool MainWindow::checkdata()
{
nameIndex=ui->cmbName->currentIndex();
qDebug()<<"index ="<<nameIndex; //this is returning either true or false should be 0,1,2...etc
if (isDirty)
{
int test=QMessageBox::warning(this, "Data has Changed", "You have made changes in the form.\n"
"Do you want to save the changes?", QMessageBox::Yes | QMessageBox::No |QMessageBox::Cancel);
if (test==QMessageBox::Yes)
{
return save();
}else if (test==QMessageBox::Cancel){
updateData(nameIndex);
isDirty=0;
return false;
}else if (test==QMessageBox::No){
updateData(nameIndex);
isDirty=0;
}
}
return true;
}
//************************************************** ***********************
//saves the changes
//************************************************** ***********************
bool MainWindow::save()
{
QSqlQuery query ;
query.prepare("UPDATE address set LName=:lname, FName=:fname, address=:address WHERE id=:id");
query.bindValue(":name", ui->txtLName->text());
query.bindValue(":fname",ui->txtFName->text());
query.bindValue(":address", ui->txtAddress->text());
query.bindValue(":id", ui->cmbName->itemData(nameIndex).toInt());
//if(!query.exec()); insert message for failed query
isDirty=0;
qDebug() << query.lastError();
query.exec();// delete for failed query test
nameIndex=ui->cmbName->currentIndex();//should get the current index to load later
updateNameComboBox();
ui->cmbName->setCurrentIndex(nameIndex);//the combobox returns to the first item
return true;
}
void MainWindow::updateRiderComboBox()
{
QSqlQuery query;
query.exec("SELECT id,LName, FName FROM address");
qDebug() << riderquery.lastError();
ui->cmbRider->clear();
while (riderquery.next())
{
ui->cmbRider->addItem(riderquery.value (2).toString()+ " "+ riderquery.value (1).toString(),riderquery.value (0).toInt());
}
SO how do I better use debug and which one? QDebug or qDebug? and any reason why this code is not working?
//************************************************** ***********************
//routine to check if data has been changed.
//if it has, give the user the option to save the changes
//************************************************** ***********************
bool MainWindow::checkdata()
{
nameIndex=ui->cmbName->currentIndex();
qDebug()<<"index ="<<nameIndex; //this is returning either true or false should be 0,1,2...etc
if (isDirty)
{
int test=QMessageBox::warning(this, "Data has Changed", "You have made changes in the form.\n"
"Do you want to save the changes?", QMessageBox::Yes | QMessageBox::No |QMessageBox::Cancel);
if (test==QMessageBox::Yes)
{
return save();
}else if (test==QMessageBox::Cancel){
updateData(nameIndex);
isDirty=0;
return false;
}else if (test==QMessageBox::No){
updateData(nameIndex);
isDirty=0;
}
}
return true;
}
//************************************************** ***********************
//saves the changes
//************************************************** ***********************
bool MainWindow::save()
{
QSqlQuery query ;
query.prepare("UPDATE address set LName=:lname, FName=:fname, address=:address WHERE id=:id");
query.bindValue(":name", ui->txtLName->text());
query.bindValue(":fname",ui->txtFName->text());
query.bindValue(":address", ui->txtAddress->text());
query.bindValue(":id", ui->cmbName->itemData(nameIndex).toInt());
//if(!query.exec()); insert message for failed query
isDirty=0;
qDebug() << query.lastError();
query.exec();// delete for failed query test
nameIndex=ui->cmbName->currentIndex();//should get the current index to load later
updateNameComboBox();
ui->cmbName->setCurrentIndex(nameIndex);//the combobox returns to the first item
return true;
}
void MainWindow::updateRiderComboBox()
{
QSqlQuery query;
query.exec("SELECT id,LName, FName FROM address");
qDebug() << riderquery.lastError();
ui->cmbRider->clear();
while (riderquery.next())
{
ui->cmbRider->addItem(riderquery.value (2).toString()+ " "+ riderquery.value (1).toString(),riderquery.value (0).toInt());
}
SO how do I better use debug and which one? QDebug or qDebug? and any reason why this code is not working?