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

Crash when calling QJSValue::hasProperty("x") from Qml on a QVector3D received from a Q_PROPERTY

    XMLWordPrintable

Details

    • 0e48d9d938 (qt/qtdeclarative/dev) 0e48d9d938 (qt/tqtc-qtdeclarative/dev) cefbda6006 (qt/qtdeclarative/6.3) 58a70bedbb (qt/qtdeclarative/6.4) 58a70bedbb (qt/tqtc-qtdeclarative/6.4) cefbda6006 (qt/qtdeclarative/6.3.2)

    Description

      From Qml, when exposing a Q_PROPERTY of type QVector3D, and passing the value of that property as an argument to a Q_INVOKABLE function, and in that function calling hasProperty("x"), it crashes.

      Here is a way of reproducing this. Sorry for the weird #include in the middle, it was just my way of keeping the whole thing into one single file along with a manual moc invocation.

      #include <QtGui/QtGui>
      #include <QtQuick/QtQuick>
      
      class Chose : public QObject
      {
      	Q_OBJECT
      	Q_PROPERTY(QVector3D f READ ff NOTIFY fChanged())
      public:
      	Chose(QObject *parent = nullptr) : QObject(parent) {}
      	QVector3D ff() const
      	{
      		return QVector3D();
      	}
      	Q_INVOKABLE void g(QJSValue v)
      	{
      		v.hasProperty("x"); // The crash occurs here
      	}
      signals:
      	void fChanged();
      };
      
      // I make moc BugQVector3DQml.cpp > ChoseMoc.cpp
      // That's why this include there:
      #include "ChoseMoc.cpp"
      
      int main(int nargs, char **args)
      {
      	QGuiApplication app(nargs,args);
      	QQuickView view;
      	Chose chose;
      	view.engine()->rootContext()->setContextProperty("chose",&chose);
      	QTemporaryFile temp_file_because_qquickview_doesnt_have_setRoot("XXXXXX.qml");
      	if(!temp_file_because_qquickview_doesnt_have_setRoot.open())
      	{
      		qCritical() << "Can't open a temporary file for writing the qml source to be loaded.";
      		return -1;
      	}
      	{
      		QTextStream stream(&temp_file_because_qquickview_doesnt_have_setRoot);
      		stream << QString(R"fin(
      				
      			import QtQuick 2.0
      			Rectangle
      			{
      				width: 100;
      				height: 100;
      				color: 'blue'
      				property var allo: chose.g(chose.f) // This leads to the crash above
      			}
      				
      			)fin");
      	}
      	view.setSource(QUrl::fromLocalFile(temp_file_because_qquickview_doesnt_have_setRoot.fileName()));
      	view.show();
      	return app.exec();
      }
      
      #ifdef _DEBUG
      #pragma comment(lib,"Qt6Quickd.lib")
      #pragma comment(lib,"Qt6Guid.lib")
      #pragma comment(lib,"Qt6Cored.lib")
      #pragma comment(lib,"Qt6Qmld.lib")
      #else
      #pragma comment(lib,"Qt6Quick.lib")
      #pragma comment(lib,"Qt6Gui.lib")
      #pragma comment(lib,"Qt6Core.lib")
      #pragma comment(lib,"Qt6Qml.lib")
      #endif
      

      Attachments

        1. backtrace.txt
          7 kB
        2. foo.pro
          0.7 kB
        3. test.cpp
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ulherman Ulf Hermann
            domg Dominic Genest
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: