PDA

View Full Version : std::string to QString?



Backslash
1st August 2007, 16:33
Hello all,

I'm trying to set the text of a QLabel, among other things, which takes QString. I need to set it however from the text in a std::string. How do I do this conversion? I've tried looking in the QString Class Reference to no avail...

I was trying to use


ui.labelName->setText(K1.getName());

but K1.getName(); returns std::string

Thanks for the time,
Backslash

Michiel
1st August 2007, 16:35
You need the static function QString::fromStdString ( const std::string & str ).

Backslash
1st August 2007, 16:47
I don't suppose this is what you mean?


ui.labelName->setText(QString::fromStdString ( const std::string & K1.getName() ));

Sorry if I'm missing something painfully simple

Thanks,
Backslash

Backslash
1st August 2007, 16:49
Sorry stupid move. I suppose I should be using:

ui.labelName->setText(QString::fromStdString (K1.getName()));

Michiel
1st August 2007, 16:50
No, I mean this:


ui.labelName->setText(QString::fromStdString( K1.getName() ));

In my previous post I gave the function signature (this included the type of the parameter).

Edit: Yep, you got it.