from "mainScreen.h"
#ifndef __MAIN_H__
#define __MAIN_H__
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <QDialog>
#include <cstdlib>
#include "main.cpp"
// connects the code to the UI
class mainScreen
: public :: QDialog,
private Ui
::mainScreenDLG {
Q_OBJECT
public:
};
#endif
#ifndef __MAIN_H__
#define __MAIN_H__
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <QDialog>
#include <cstdlib>
#include "main.cpp"
// connects the code to the UI
class mainScreen : public :: QDialog, private Ui::mainScreenDLG
{
Q_OBJECT
public:
mainScreen(QDialog *parent = 0);
};
#endif
To copy to clipboard, switch view to plain text mode
from "mainScreen.cpp"
#include <QApplication>
#include <QDataStream>
#include <QtGui>
#include <cstdlib>
#include <ctime>
#include "ui_mainScreen.h"
#include "mainScreen.h"
// code to begin the programme
mainScreen
::mainScreen(QDialog *parent
)
{
setupUi(this);
// declaration of variables
int operand1, operand2, divisi1, divisi2, sumAnswer, subAnswer, multiAnswer, divisiAnswer, i;
bool selectSum, selectSub, selectMulti, selectDivisi;
// timer for random generator
srand (time(0));
// selects which operations are being used
if (selectSum = true)
{
operand1 = rand()/1638 + 1;
operand2 = rand()/1638 + 1;
lblOperand1.text()->setText(operand1);
lblOperand2.text()->setText(operand2);
sumAnswer = txtAnswer.text();
}
void mainScreen::on_btnCheck_clicked()
{
if (selectSum = true)
{
// if the correct answer is put in, then a message box shows this
if (operand1 + operand2 == sumAnswer)
{
}
// if the incorrect answer is put in, then a message box shows this
if (operand1 + operand2 != sumAnswer)
{
QMessageBox::about(this,
"Incorrect",
"Incorrect. The correct answer is" + sumAnswer
);
}
}
};
#include <QApplication>
#include <QDataStream>
#include <QtGui>
#include <cstdlib>
#include <ctime>
#include "ui_mainScreen.h"
#include "mainScreen.h"
// code to begin the programme
mainScreen::mainScreen(QDialog *parent)
{
setupUi(this);
// declaration of variables
int operand1, operand2, divisi1, divisi2, sumAnswer, subAnswer, multiAnswer, divisiAnswer, i;
bool selectSum, selectSub, selectMulti, selectDivisi;
// timer for random generator
srand (time(0));
// selects which operations are being used
if (selectSum = true)
{
operand1 = rand()/1638 + 1;
operand2 = rand()/1638 + 1;
lblOperand1.text()->setText(operand1);
lblOperand2.text()->setText(operand2);
sumAnswer = txtAnswer.text();
}
void mainScreen::on_btnCheck_clicked()
{
if (selectSum = true)
{
// if the correct answer is put in, then a message box shows this
if (operand1 + operand2 == sumAnswer)
{
QMessageBox::about(this, "Correct!", "Correct!");
}
// if the incorrect answer is put in, then a message box shows this
if (operand1 + operand2 != sumAnswer)
{
QMessageBox::about(this, "Incorrect", "Incorrect. The correct answer is" + sumAnswer);
}
}
};
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
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*’
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!!
Bookmarks