Quote Originally Posted by jamadagni
I am first reading C++ GUI programming in Qt to get a general idea of Qt and along the way I have got an idea of C++ specialties (over C which I know somewhat okay) of what a class is etc.

But I do not understand a few things:

Sometimes you have class.function() and sometimes class->function()

I don't understand the difference.

Also between & and *

void setEditText ( const QString & text )
void setValidator ( const QValidator * validator )

I have seen * going into the declaration of a function in C, but & -- ? But I note that & inside the argument occurs only for signals and slots. Something special here?

Last: I see the word const *after* the declaration of a function:

int currentIndex () const

What does this mean?
If you create a class on the heap with the "NEW" operator then you use "->" otherwise you are creating a class on the stack and you use the "." operator when referencing members. Here is some code which illustrates both methods.
Qt Code:
  1. void homestead::GenerateXTabAllCounties(){
  2. //////////// Cntyname vs MSHEC for all counties ///////////////
  3. QString sQuestion;
  4. sQuestion.append("Do you want to generate an All Counties\n");
  5. sQuestion.append("cross tab report for Homestead?\n");
  6. int reply = QMessageBox::question(this, tr("QMessageBox::showQuestion()"),
  7. sQuestion, QMessageBox::Yes, QMessageBox::No);
  8. if (reply == QMessageBox::Yes){
  9. ui.leStatus->setText("Preparing XTab Report...");
  10. QString queryStr = "SELECT cntyname, M1,M2,M3,M4,S1,S2,S3,S4,VA,";
  11. queryStr.append("(SUM(M1)+SUM(M2)+SUM(M3)+SUM(M4)+SUM(S1)+SUM(S2)+SUM(S3)+SUM(S4)+SUM(VA)) AS Totals ");
  12. queryStr.append("FROM(SELECT cntyname, ");
  13. queryStr.append("SUM(CASE WHEN offuse = 'M-1' THEN 1 ELSE 0 END)AS M1,");
  14. queryStr.append("SUM(CASE WHEN offuse = 'M-2' THEN 1 ELSE 0 END)AS M2,");
  15. queryStr.append("SUM(CASE WHEN offuse = 'M-3' THEN 1 ELSE 0 END)AS M3,");
  16. queryStr.append("SUM(CASE WHEN offuse = 'M-4' THEN 1 ELSE 0 END)AS M4,");
  17. queryStr.append("SUM(CASE WHEN offuse = 'S-1' THEN 1 ELSE 0 END)AS S1,");
  18. queryStr.append("SUM(CASE WHEN offuse = 'S-2' THEN 1 ELSE 0 END)AS S2,");
  19. queryStr.append("SUM(CASE WHEN offuse = 'S-3' THEN 1 ELSE 0 END)AS S3,");
  20. queryStr.append("SUM(CASE WHEN offuse = 'S-4' THEN 1 ELSE 0 END)AS S4,");
  21. queryStr.append("SUM(CASE WHEN offuse = 'VA' THEN 1 ELSE 0 END)AS VA ");
  22. queryStr.append("FROM hap");
  23. queryStr.append(this->dbYear);
  24. queryStr.append(".property_");
  25. queryStr.append(" GROUP BY cntyname ORDER BY cntyname)");
  26. queryStr.append("GROUP BY cntyname,M1,M2,M3,M4,S1,S2,S3,S4,VA ORDER BY cntyname");
  27. QSqlQueryModel *XtabModel = NEW QSqlQueryModel;
  28. XtabModel->setQuery(queryStr);
  29. if (XtabModel->rowCount() > 0){
  30. ui.leStatus->setText("Processing XTab rows ...");
  31. // generate html code for MS (offuse) versus Percent Exmption for all counties
  32. int nRecs = XtabModel->rowCount();
  33. int totM1 = 0;
  34. int totM2 = 0;
  35. int totM3 = 0;
  36. int totM4 = 0;
  37. int totS1 = 0;
  38. int totS2 = 0;
  39. int totS3 = 0;
  40. int totS4 = 0;
  41. int totVA = 0;
  42. int totTotals = 0;
  43. QDate dateToday = QDate::currentDate();
  44. QString XTabName = "D_";
  45. XTabName.append(dateToday.toString("MMdd"));
  46. XTabName.append("_XTab_CntyName_vs_MSHEC");
  47. XTabName.append(".HTML");
  48. XTabName.prepend("reports/");
  49. QFile file(XTabName);
  50. if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
  51. ui.leStatus->setText("Can't open XTab_CntyName_vs_MSHEC html file for output");
  52. return;
  53. }
  54. QTextStream out(&file);
  55. //mod the lines below to change code to batches between dates.
  56. out << homestead::HTML_Header1 ;
  57. out << "Homestead " << this->dbYear << " Crosstab Report for All Counties ";
  58. out << homestead::HTML_Header2 << "\n";
  59. out << "<TABLE width='100%' align=center><TR><TH>Homestead " ;
  60. out << this->dbYear << " Crosstab Report for All Counties " ;
  61. out << "</TH></TR></TABLE><P></P>" << "\n";
  62. out << "<TABLE width='100%' ><B><TR>";
  63. out << "<TH align=left width='20%'>County Name</TH>";
  64. out << "<TH width='8%' align=right>M1</TH>";
  65. ...
  66. delete *XtabModel
  67. }
To copy to clipboard, switch view to plain text mode