3
I need the text of a lineEdit
is equal to a variable string.
I’m using this code:
void MainWindow::on_pushButton_clicked(){
string texto;
texto= "mensagem";
ui->lineEdit->setText(texto);
}
3
I need the text of a lineEdit
is equal to a variable string.
I’m using this code:
void MainWindow::on_pushButton_clicked(){
string texto;
texto= "mensagem";
ui->lineEdit->setText(texto);
}
3
Do so:
void MainWindow::on_pushButton_clicked(){
Qstring texto;
texto = "mensagem";
ui->lineEdit->setText(texto);
}
Or better yet:
void MainWindow::on_pushButton_clicked(){
ui->lineEdit->setText(QStringLiteral("mensagem"));
}
I put in the Github for future reference.
The QStringLiteral
is a macro present in Qt 5 that creates a literal like QString
without having to convert at runtime.
The setText
of LineEdit
expecting a QString
and not a string
standard of C++, so it didn’t work.
Browser other questions tagged c++ string qt
You are not signed in. Login or sign up in order to post.
It worked, thank you very much
– Samuel Brati Favarin
@Samuelbratifavarin if it worked marque the answer as correct, if you do not know how to do this read the tips here on how to use the site: http://meta.pt.stackoverflow.com/q/1078/3635
– Guilherme Nascimento
What is the difference between 'Qstring' and Qstringliteral'?
– mrlucasrib
@Luke the 1st. is the type and the 2nd. is a macro p/ generate the literal without converting, if you want to know more details, ask a question.
– Maniero