Can't get the SQL statement in this function to work. I've gone over and over it and rewritten it multiple times but just can't see what's wrong.
The function sets up a number of QActions for a popup menu which all works fine.
The commented lines are the new code added to retrieve the saved preferences from an SQLite database (sets whether actions are checked or not on launch) which is what's not working.
Every iteration of the for loop which calls userVars.value() errors with -
QSqlQuery::value: not positioned on a valid record.
Also debug of userVars.value(i) returns QVariant(,)
Heres the functions :
QMenu* Cust
::f_cust_colFilterPopUp() {
temp_details << "Customer Id"<< "Surname"<< "Name"<< "Address"<< "City"<< "State"<< "Postcode"
<< "Country"<< "Business ph.1"<< "Home ph.1"<< "Business ph.2"<< "Home ph.2"
<<"Mobile"<< "Fax"<< "Scheduled Jobs"<< "Non Scheduled Jobs"<< "Incomplete Jobs"
<<"Total Jobs"<< "Jobs to Invoice"<< "Total Invoiced"<< "Unpayed Invoices";
//QString to replace * in SQL statement, using * for debuging atm
/*temp_checked << "rowid" << "showSurname"<< "showName"<< "showAddress"<< "showCity"<<
"showState"<< "showPcode"<< "showCountry"<< "showBPhone1"<<
"showHPhone1"<< "showBPhone2"<< "showHPhone2"<< "showMobPhone"<<
"showFax"<< "showScheduledJobs"<< "showUnscheduledJobs"<<
"showIncompleteJobs"<< "showTotalJobs"<< "showToInvoice"<<
"showInvoiced"<< "showOutInvoice";*/
if (!userVars.exec("SELECT * FROM savedData WHERE rowid=1")) //exec SQL and error check
{
QString error
= userVars.
lastError().
text();
qApp->tr("Unable to execute sql query.\n"
+ userVars.lastError().text().toAscii() +
}
qmenu_cust_popUpMenu
= new QMenu;
for(int i=0;i<20;i++)
{
qaction_cust_popUpAction
[i
] = new QAction(qApp
->activeWindow
());
qaction_cust_popUpAction[i]->setCheckable(true);
qaction_cust_popUpAction[i]->setText(temp_details.at(i));
bool checked = userVars.value(i).toBool(); //get field and convert to bool
qaction_cust_popUpAction[i]->setChecked(checked); //set checkbox value
qmenu_cust_popUpMenu->addAction(qaction_cust_popUpAction[i]);
connect(qaction_cust_popUpAction[i], SIGNAL(changed()), this, SLOT(sl_cust_filter()));
qDebug()<<(userVars.value(i)); //debug returns QVariant(,)
}
return qmenu_cust_popUpMenu;
}
QMenu* Cust::f_cust_colFilterPopUp()
{
QSqlQuery userVars;
QStringList temp_details;
QString temp_checked;
temp_details << "Customer Id"<< "Surname"<< "Name"<< "Address"<< "City"<< "State"<< "Postcode"
<< "Country"<< "Business ph.1"<< "Home ph.1"<< "Business ph.2"<< "Home ph.2"
<<"Mobile"<< "Fax"<< "Scheduled Jobs"<< "Non Scheduled Jobs"<< "Incomplete Jobs"
<<"Total Jobs"<< "Jobs to Invoice"<< "Total Invoiced"<< "Unpayed Invoices";
//QString to replace * in SQL statement, using * for debuging atm
/*temp_checked << "rowid" << "showSurname"<< "showName"<< "showAddress"<< "showCity"<<
"showState"<< "showPcode"<< "showCountry"<< "showBPhone1"<<
"showHPhone1"<< "showBPhone2"<< "showHPhone2"<< "showMobPhone"<<
"showFax"<< "showScheduledJobs"<< "showUnscheduledJobs"<<
"showIncompleteJobs"<< "showTotalJobs"<< "showToInvoice"<<
"showInvoiced"<< "showOutInvoice";*/
if (!userVars.exec("SELECT * FROM savedData WHERE rowid=1")) //exec SQL and error check
{
QString error = userVars.lastError().text();
QMessageBox::critical(0, qApp->tr("Query Failed"),
qApp->tr("Unable to execute sql query.\n"
+ userVars.lastError().text().toAscii() +
"\n Click cancel to exit."), QMessageBox::Cancel);
}
qmenu_cust_popUpMenu = new QMenu;
for(int i=0;i<20;i++)
{
qaction_cust_popUpAction[i] = new QAction(qApp->activeWindow());
qaction_cust_popUpAction[i]->setCheckable(true);
qaction_cust_popUpAction[i]->setText(temp_details.at(i));
bool checked = userVars.value(i).toBool(); //get field and convert to bool
qaction_cust_popUpAction[i]->setChecked(checked); //set checkbox value
qmenu_cust_popUpMenu->addAction(qaction_cust_popUpAction[i]);
connect(qaction_cust_popUpAction[i], SIGNAL(changed()), this, SLOT(sl_cust_filter()));
qDebug()<<(userVars.value(i)); //debug returns QVariant(,)
}
return qmenu_cust_popUpMenu;
}
To copy to clipboard, switch view to plain text mode
Bookmarks