tags:

views:

416

answers:

2

Dear All,

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 setText accept them (other functions returning char do not give me problems).

What should I do? Thanks!

Giuseppe

+2  A: 

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

Georg
Ugly, I was hoping to find something better. I have learnt in Meyer's books to use string instead of char whenever possible: how is it possible for QT not handle strings properly?
Giuseppe
@Giuseppe: Qt has its own QTL and its own string class. Most Qt containers and QString can be converted from/to their STL counterparts if your version of Qt was compiled in STL compatibility mode. AFAIK this mode is the default.
rpg
They expect you to use `QString`. I'd have a look at rpg's answer, looks way better than mine. Another possibility is of course to hack Qt's code, that should be a matter of 10 minutes.
Georg
+6  A: 

Try this:

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

You will need Qt with STL support.

rpg
Great! Will try it now.
Giuseppe
THANKS!!! IT WORKED!! You are a wizard ^__^
Giuseppe
You're welcome :-)
rpg