from "mainScreen.h"
Qt Code:
  1. #ifndef __MAIN_H__
  2. #define __MAIN_H__
  3. #include <QMainWindow>
  4. #include <QApplication>
  5. #include <QPushButton>
  6. #include <QDialog>
  7. #include <cstdlib>
  8. #include "main.cpp"
  9.  
  10. // connects the code to the UI
  11. class mainScreen : public :: QDialog, private Ui::mainScreenDLG
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. mainScreen(QDialog *parent = 0);
  17. };
  18.  
  19.  
  20. #endif
To copy to clipboard, switch view to plain text mode 

from "mainScreen.cpp"

Qt Code:
  1. #include <QApplication>
  2. #include <QDataStream>
  3. #include <QtGui>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include "ui_mainScreen.h"
  7. #include "mainScreen.h"
  8.  
  9.  
  10.  
  11.  
  12. // code to begin the programme
  13. mainScreen::mainScreen(QDialog *parent)
  14.  
  15. {
  16. setupUi(this);
  17.  
  18.  
  19. // declaration of variables
  20. int operand1, operand2, divisi1, divisi2, sumAnswer, subAnswer, multiAnswer, divisiAnswer, i;
  21. bool selectSum, selectSub, selectMulti, selectDivisi;
  22.  
  23. // timer for random generator
  24. srand (time(0));
  25.  
  26. // selects which operations are being used
  27. if (selectSum = true)
  28. {
  29.  
  30. operand1 = rand()/1638 + 1;
  31. operand2 = rand()/1638 + 1;
  32. lblOperand1.text()->setText(operand1);
  33. lblOperand2.text()->setText(operand2);
  34. sumAnswer = txtAnswer.text();
  35.  
  36. }
  37. void mainScreen::on_btnCheck_clicked()
  38. {
  39. if (selectSum = true)
  40. {
  41. // if the correct answer is put in, then a message box shows this
  42. if (operand1 + operand2 == sumAnswer)
  43. {
  44. QMessageBox::about(this, "Correct!", "Correct!");
  45. }
  46.  
  47. // if the incorrect answer is put in, then a message box shows this
  48. if (operand1 + operand2 != sumAnswer)
  49. {
  50. QMessageBox::about(this, "Incorrect", "Incorrect. The correct answer is" + sumAnswer);
  51. }
  52. }
  53. };
To copy to clipboard, switch view to plain text mode 

i want to make the text of lblOperand1 (which is a QLabel) the value of operand1
but i get the error
Qt Code:
  1. src/mainScreen.cpp:32: error: request for member ‘text’ in ‘((mainScreen*)this)->mainScreen::<anonymous>.Ui::mainScreenDLG::<anonymous>.Ui_mainScreenDLG::lblOperand1’, which is of non-class type ‘QLabel*’
To copy to clipboard, switch view to plain text mode 
i checked and made sure that the label was named and referenced to correctly

i also want to be able to use the "operand1" variable in "void mainScreen:n_btnCheck_clicked()"
but it tells me that the variables "selectSum", "operand1" etc are not declared in that scope?

thankyou in advance!!