Qt Call fails in Release Mode

2019-09-02 15:54发布

问题:

I've developed an application using Qt, VS2013 and Boost. It runs fine in Debug mode. But fails to run in Release mode. Here's a piece of code that runs fine while debugging but throws an exception in release mode:

std::string str = ui.labels->toPlainText().toStdString();

This call on the other hand works fine:

QString str = ui.labels->toPlainText();

Is there anything wrong with those lines of code? Other boost calls work fine. Thanks.

回答1:

You're probably trying to do too many things at once, and that makes it hard to pinpoint where it fails. Try it step-by-step:

QString const text = ui.labels->toPlainText();
QByteArray const utf8 = text.toUtf8();
auto const str = utf8.toStdString();