How to use std::string in a QLineEdit?
Question
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
Solution
Try this:
std::string a = "aaa";
lineEdit->setText(QString::fromStdString(a));
You will need Qt with STL support.
OTHER TIPS
There's no constructor for QString
that takes a std::string
. Convert it first to a C string using std::string::c_str()
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow