-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.6.3
-
None
-
-
df684931c (dev), 14bb25f69 (6.8)
We encountered an issue where a value returned from QJSEngine::evaluate returns a null QString. This caused problems when writing the result to a SQL database where we get NULL instead of an empty string (Previously we used QScriptEngine where it worked as expected).
This behavior is inconsistent with a QJSValue constructed with either an empty or null QString. In that case value.toString().isNull() is false.
I would expect the same for the evaluate result.
Here's a small example:
#include <QCoreApplication> #include <QJSEngine> #include <QJSValue> #include <QString> #include <QVariant> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QJSEngine engine; const auto evalResult = engine.evaluate(R"( function f() { return ""; } f(); )"); const auto evalResultStr = evalResult.toString(); qDebug() << "QJSEngine::evaluate : " << (evalResultStr.isNull() ? "null" : "not null"); QJSValue jsValueNullStr = QString{}; qDebug() << "QJSValue(QString()) : " << (jsValueNullStr.isNull() ? "null" : "not null"); QJSValue jsValueEmptyStr = QStringLiteral(""); qDebug() << "QJSValue(QString(\"\")): " << (jsValueEmptyStr.isNull() ? "null" : "not null"); }
This is the output:
QJSEngine::evaluate : null QJSValue(QString()) : not null QJSValue(QString("")): not null
- resulted from
-
QTBUG-37197 REGRESSION: Warning "Unable to assign QString to QByteArray"
-
- Closed
-