Yes the notebook part IS a plugin, and no, I didn't provide a constructor. I thought a default constructor might be provided by Qt... I just implemented the extra functions I need for the comboBox.

The .h file is in this post, this is the cpp file:

Qt Code:
  1. void AreacodesCombobox::initializeFields()
  2. {
  3. QString blank = " ";
  4. setSelectedAreacode(blank);
  5. setSelectedLocale(blank);
  6. clear();
  7. }
  8.  
  9. void AreacodesCombobox::on_returnPressed()
  10. {
  11. QString aLocale=currentText();
  12. if ((aLocale.trimmed().length() > 1) && (aLocale != QString(selectedLocale()).toUpper()))
  13. {
  14. QString searchText= ("UCASE(locale) like '%");
  15. searchText.append(aLocale.trimmed().toUpper());
  16. searchText.append("%' order by LOCALE");
  17. QString clause = searchWordsClause(aLocale, "locale", "AND", false,"locale");
  18. clause.prepend("SELECT Areacode, Locale FROM AreacodesView WHERE ");
  19. clause.append(" Order by Locale");
  20. QSqlQuery query(clause);
  21. if (query.isActive()) // successful execution
  22. {
  23. if (query.size()==0)
  24. {
  25. QApplication::beep ();
  26. QMessageBox::warning(this, tr("Postcode Search"),
  27. tr("No match found.\nCheck the spelling and try again."), QMessageBox::Ok);
  28. setFocus();
  29. }
  30. else
  31. {
  32. clear();
  33. while (query.next())
  34. {
  35. QString locale = query.value(0).toString();
  36. addItem(locale);
  37. }
  38. if (query.size()==1)
  39. QComboBox::setCurrentIndex(1);
  40. else
  41. {
  42. // comboBox()->select(1, true);
  43. QComboBox::showPopup();
  44. }
  45. }
  46. }
  47. else
  48. {
  49. QApplication::beep ();
  50. QMessageBox::warning(this, tr("SQL Error"),
  51. query.lastError().text(), QMessageBox::Ok);
  52. }
  53. // else if (model->query().isSelect()) // is a select statement
  54. }
  55. }
To copy to clipboard, switch view to plain text mode