0

I have created a dialog box using the qt designer. it generate me a .ui, cpp and header.

the cpp is defined :

DialogAbout::DialogAbout(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogAbout)
{
    ui->buildversion->setText("toto");
    ui->setupUi(this);
}

header

class DialogAbout : public QDialog
{
    Q_OBJECT

public:
    explicit DialogAbout(QWidget *parent = 0);
    ~DialogAbout();
    QLabel *buildversion;

private:
    Ui::DialogAbout *ui;
};

and the UI looks like :

enter image description here

My app is crashing each time I'm accessing the this dialog box when trying to

ui->buildversion->setText("toto");

Any idea ?

Thanks

Seb
  • 2,929
  • 4
  • 30
  • 73

1 Answers1

5

You should setupUi before:

DialogAbout::DialogAbout(QWidget *parent) :
   QDialog(parent),
   ui(new Ui::DialogAbout)
{
    ui->setupUi(this);
    ui->buildversion->setText("toto");
}

Once setupUi() function has been called, it becomes possible to modify the user interface as needed.
You can learn more about using a designer UI file in your application from docs.

tema
  • 1,115
  • 14
  • 33