#ifndef LOTTO_H
#define LOTTO_H
#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
#include <QGridLayout>
class lotto : public QWidget
{
Q_OBJECT
private:
//widget data members
QLabel* numbersLabel;
QTextEdit* numEdit;
QPushButton* lotusButton;
public slots:
int generateLotteryNumbers ();
void displayNumbers();
public:
lotto();
};
#endif // LOTTO_H
#include "lotto.h"
#include <stdlib.h>
#include <time.h>
#include <QWidget>
#include <QGridLayout>
#include <iostream>
#include <sstream>
#include <QString>
#include "lotto.h"
using namespace std;
lotto::lotto(){
setWindowTitle("Lotto Numbers");
QGridLayout* layout = new QGridLayout(this);
lotusButton = new QPushButton ("Lotto Numbers");
numbersLabel = new QLabel ("Your lucky numbers are:");
numEdit = new QTextEdit();
layout->addWidget(lotusButton, 0,0);
layout->addWidget(numbersLabel, 1,0);
layout->addWidget(numEdit, 1,1);
setLayout(layout);
//connect signals and slots
connect(lotusButton,SIGNAL(clicked()),this, SLOT(generateLotteryNumbers()));
}
int lotto::generateLotteryNumbers (){
srand ( time(NULL) );
int i, j, num, duplicates, numbers[6];
for ( i = 0; i < 6; i++ ) {
do {
num = 1 + rand()%49;
duplicates = 0;
for ( j = 0; j < i; j++ ) {
if ( numbers[ j ] == num ) duplicates = 1;
}
}
while (duplicates);
numbers[ i ] = num;
}
}
void lotto::displayNumbers(){
numEdit->setText(QString::number(generateLotteryNumbers()));
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QWidget>
#include <QLabel>
#include <QTimer>
#include <QLineEdit>
#include <QPushButton>
#include <QStringList>
class MainWindow : public QWidget {
Q_OBJECT
public:
MainWindow();
void setTimer();
void DisplayMessage();
public slots:
void changeTimerValue();
void toggleTimer();
void TimeOut();
private:
static QStringList m_messages;
static int m_current_message;
QTimer* m_timer;
QLineEdit* m_timer_entry;
QPushButton* m_start_timer;
//QPushButton* m_set_timer;
QLabel* lblRandomMsg;
QLabel* lblMsg;
bool m_started;
};
#endif // MAINWINDOW_H
#include "lotto.h"
#include <stdlib.h>
#include <time.h>
#include <QWidget>
#include <QGridLayout>
#include <iostream>
#include <sstream>
#include <QString>
#include "lotto.h"
using namespace std;
lotto::lotto(){
setWindowTitle("Lotto Numbers");
QGridLayout* layout = new QGridLayout(this);
lotusButton = new QPushButton ("Lotto Numbers");
numbersLabel = new QLabel ("Your lucky numbers are:");
numEdit = new QTextEdit();
layout->addWidget(lotusButton, 0,0);
layout->addWidget(numbersLabel, 1,0);
layout->addWidget(numEdit, 1,1);
setLayout(layout);
//connect signals and slots
connect(lotusButton,SIGNAL(clicked()),this, SLOT(generateLotteryNumbers()));
}
int lotto::generateLotteryNumbers (){
srand ( time(NULL) );
int i, j, num, duplicates, numbers[6];
for ( i = 0; i < 6; i++ ) {
do {
num = 1 + rand()%49;
duplicates = 0;
for ( j = 0; j < i; j++ ) {
if ( numbers[ j ] == num ) duplicates = 1;
}
}
while (duplicates);
numbers[ i ] = num;
}
}
void lotto::displayNumbers(){
numEdit->setText(QString::number(generateLotteryNumbers()));
}
I try to display 6 lotto numbers in a textedit box. Is it better to use a lineedit? The textbox remains empty when I click the lotto number button. Why? How can I get the textbox (or the linebox) to display the numbers?