How to use std::string in a QLineEdit?

我怕爱的太早我们不能终老 提交于 2021-02-16 13:29:09

问题


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


回答1:


Try this:

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

You will need Qt with STL support.




回答2:


There's no constructor for QString that takes a std::string. Convert it first to a C string using std::string::c_str().



来源:https://stackoverflow.com/questions/1537164/how-to-use-stdstring-in-a-qlineedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!