Hi!
I want to use the QStringList *listaMatriculasValidas inside the "void IdDoAutomovelDialog:n_lineEdit_textChanged()" private slot, where the connection is made automatically by the setupUi()!
How can i access it where "x marks the spot"
Here is the code:
Qt Code:
  1. #include <QtGui>
  2.  
  3. #include "IdDoAutomovelDialog.h"
  4.  
  5. IdDoAutomovelDialog:: IdDoAutomovelDialog(QWidget *parent) : QDialog(parent){
  6. setupUi(this);
  7.  
  8. //Validar a matrÃ*cula introduzida ( http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )
  9. QStringList *listaMatriculasValidas = new QStringList;
  10. listaMatriculasValidas->operator <<("[A-Za-z]{2,2}-[0-9]{2,2}-[0-9]{2,2}");
  11. listaMatriculasValidas->operator <<("[0-9]{2,2}-[0-9]{2,2}-[A-Za-z]{2,2}");
  12. listaMatriculasValidas->operator <<("[0-9]{2,2}-[A-Za-z]{2,2}-[0-9]{2,2}");
  13. QRegExp regExp(listaMatriculasValidas->join("|"));
  14. lineEdit->setValidator(new QRegExpValidator(regExp, this));
  15.  
  16. //Definir acções
  17. connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
  18. connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  19. }
  20.  
  21. void IdDoAutomovelDialog::on_lineEdit_textChanged(){
  22. okButton->setEnabled(lineEdit->hasAcceptableInput());
  23.  
  24. ////////////////////////////
  25. // //
  26. // X marks the spot
  27. // //
  28. ////////////////////////////
  29.  
  30. //Limpar chapa
  31. labelDescSerie->setText("?");
  32.  
  33. //Verificar qual a série de matrÃ*cula
  34. QLineEdit newlineEdit;
  35. newlineEdit.setText(lineEdit->text());
  36.  
  37. QRegExp serie;
  38. serie.setPattern("[A-Za-z]{2,2}-[0-9]{2,2}-[0-9]{2,2}");
  39. QRegExpValidator validator(serie,this);
  40.  
  41. //Chapa de modelo anterior a 1992
  42. newlineEdit.setValidator(&validator);
  43. if(newlineEdit.hasAcceptableInput())
  44. labelDescSerie->setText("Chapa de modelo anterior a 1992");
  45.  
  46. //Chapa de modelo utilizado entre 1992 e 2005
  47. serie.setPattern("[0-9]{2,2}-[0-9]{2,2}-[A-Za-z]{2,2}");
  48. validator.setRegExp(serie);
  49. if(newlineEdit.hasAcceptableInput())
  50. labelDescSerie->setText("Chapa de modelo utilizado entre 1992 e 2005");
  51.  
  52. //Chapa de modelo posterior a 2005
  53. serie.setPattern("[0-9]{2,2}-[A-Za-z]{2,2}-[0-9]{2,2}");
  54. validator.setRegExp(serie);
  55. if(newlineEdit.hasAcceptableInput())
  56. labelDescSerie->setText("Chapa de modelo posterior a 2005");
  57. }
To copy to clipboard, switch view to plain text mode 

The idea is not to repeat the strings and the use Iteration to optimize the code.
Thanks