-
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
-
For Gerrit Dashboard: QTBUG-125611 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
570643,8 | QJSEngine: Treat empty string literals as non-null, empty QStrings | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
572107,2 | QJSEngine: Treat empty string literals as non-null, empty QStrings | 6.8 | qt/qtdeclarative | Status: MERGED | +2 | 0 |