Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

I have a simple question.



  • I have a simple question about qt programming.

    I want to using the ui file for add component.
    For example, add QLabel component by modify ui file.

    But text of label is need change.
    So I try code llike above...

    QLabel *label1 = ui->label;
    label->setText("change text");
    ui->setupUi(this);

    The result is crush.
    Crush message is above...

    "The program has unexpectedly finished.
    The process was ended forcefully."

    Can't I using this coding style??



  • Hi, ui->setupUi(this) creates all the stuff in your window, like the ui->label you're copying, so try to change the order of the statements to:

    ui->setupUi(this);
    QLabel *label1 = ui->label;
    label1->setText("change text");
    

Log in to reply