I need the text of a lineEdit
to equal a string variable.
I'm using this code:
void MainWindow::on_pushButton_clicked(){
string texto;
texto= "mensagem";
ui->lineEdit->setText(texto);
}
I need the text of a lineEdit
to equal a string variable.
I'm using this code:
void MainWindow::on_pushButton_clicked(){
string texto;
texto= "mensagem";
ui->lineEdit->setText(texto);
}
Do this:
void MainWindow::on_pushButton_clicked(){
Qstring texto;
texto = "mensagem";
ui->lineEdit->setText(texto);
}
Or even better:
void MainWindow::on_pushButton_clicked(){
ui->lineEdit->setText(QStringLiteral("mensagem"));
}
The QStringLiteral
is a macro present in Qt 5 that creates a literal of type QString
without having to do conversion at runtime.
The setText
of LineEdit
expects a QString
and not a string
default of C ++, so it did not work.