0
#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>
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 (){
   return (rand() % 49)+ 1;
}
void lotto::displayNumbers(){
    numEdit->setText(generateLotteryNumbers());
}

I can't get the random numbers to be displayed in the text box. why?

2
Contributors
3
Replies
14
Views
4 Years
Discussion Span
Last Post by tinstaafl
0

You can use stringstream

Also it appears your generateLotteryNumbers () will only produce one number. You might want to recode it with a loop and maybe return a string of the numbers, or maybe an array of int's

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.