简体   繁体   中英

Qt 5 App crashes with "qLineEdit::setText"

My app crashes while running to this line in my QMainWindow constructor:

ui->timeEdit->setText(QString::number(this->time));

To make sure I did nothing wrong with QString::number(this->time) , I also tried:

ui->timeEdit->setText("QString::number(this->time)");

Still doesn't work.

The constructor:

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    this->time = 0;
    ui->timeEdit->setText(QString::number(this->time));

    ui->setupUi(this);
}

If you call that line before setupUI that means that timeEdit object is not yet created causing your application to crash. You should never reference any ui objects before the execution of setupUI .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM