Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use std::string in a QLineEdit?

I have the following problem. I am trying to integrate a large code written by me with a Qt interface.

Some of my functions return std::string. I did not succeed in making QLineEdit::setText accept them (other functions returning char do not give me problems).

What should I do? Thanks!
Giuseppe

like image 622
Giuseppe Avatar asked Oct 08 '09 11:10

Giuseppe


People also ask

Is string the same as std :: string?

There is no functionality difference between string and std::string because they're the same type.

How can I get data from line edit in Qt?

So in our Qt widget application, we have the lineEdit element and a pushbutton whose name is "pushButton". The retrieval of the value of the lineEdit element is done when the push button is clicked. So inside of this clicked function, we specify the variable, textvalue, and set it equal to, ui->lineEdit->displayText();


1 Answers

Try this:

std::string a = "aaa";
lineEdit->setText(QString::fromStdString(a));

You will need Qt with STL support.

like image 144
rpg Avatar answered Oct 14 '22 18:10

rpg