そのサンプル コードを試しているところ、visualc++ 2010 でクラッシュします。
QString fileName = "helloworld";
std::string str = fileName.toStdString();
そのサンプル コードを試しているところ、visualc++ 2010 でクラッシュします。
QString fileName = "helloworld";
std::string str = fileName.toStdString();
QString を std::string に変換するには?
QString を std::string に変換するときに覚えておくべきことの 1 つは、QString が UTF-16 でエンコードされているのに対し、std::string はエンコードされているという事実です。
QString qs;
// Either this if you use UTF-8 anywhere
std::string utf8_text = qs.toUtf8().constData();
// or this if you on Windows :-)
std::string current_locale_text = qs.toLocal8Bit().constData();
std::string str(fileName.toStdString());
str に qstring のコピーを含めたい場合