Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67240

QQmlExpression::hasError() always returns false

    XMLWordPrintable

Details

    Description

      QQmlExpression::hasError() always returns false even though given expression is not valid.
      Also, QQmlExpression::error() is not set with invalid expression.
      This makes errors in expression undetectable.

      Here's example program:

      #include <QtCore/QDebug>
      #include <QtCore/QCoreApplication>
      #include <QtQml/QQmlEngine>
      #include <QtQml/QQmlComponent>
      #include <QtQml/QQmlExpression>
      
      auto main(int argc, char **argv) -> int
      {
          QCoreApplication app{argc, argv};
          QQmlEngine engine;
          QObject scope;
          QQmlExpression expr{engine.rootContext(), &scope, "{"};
          expr.evaluate();
          qDebug() << "error?" << expr.hasError();
          return 0;
      }
      

      I expect the output be "error? true", but here's the actual output:

      <Unknown File>: SyntaxError: Expected token `}'
      error? false
      

      Although the SyntaxError is printed by Qt itself, hasError() still returns false.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            xylosper Byoung-young Lee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes