1

I am trying to covert a string to a QString so I can display that QString on a QLineEdit or a QLabel. Here is the a piece of the code that I have so far

char buff[100];
fgets(buff, sizeof(buff), fp);

//the buff[0] and buff[1] are two char values that I add up to make a string
std::string latitude = std::string() +  buff[0]  +  buff[1]; 
QString::fromStdString(latitude);

this->ui->lineEdit->setText(latitude);
Ilya
  • 4,583
  • 4
  • 26
  • 51
TheBBC
  • 79
  • 1
  • 8

1 Answers1

5

Function QString::fromStdString returns a copy of the string. But in your code result of this function is just ignored. Try this:

const QString str = QString::fromStdString(latitude);

After it you will have QString str which content is the same as content of std::string latitude.

Ilya
  • 4,583
  • 4
  • 26
  • 51
  • 1
    One caveat to keep in mind is that `QString::fromStdString()` expects the input string to be UTF-8. That's fine on most platforms, but *probably* not what you want on Windows. – MrEricSir Aug 18 '15 at 05:41