#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?

Right off the bat it looks like setText is expecting a string but you're passing an int

how do I pass an integer?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.