mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 21:03:17 +02:00
Merge pull request #15975 from huffman/fix/interactive-window-qmlto-script-crash
BUGZ-1028: Fix qmlToScript getting called on script thread and causing crash
This commit is contained in:
commit
abeba03a7e
1 changed files with 19 additions and 5 deletions
|
@ -187,8 +187,11 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
if (status == QQuickView::Ready) {
|
if (status == QQuickView::Ready) {
|
||||||
QQuickItem* rootItem = _dockWidget->getRootItem();
|
QQuickItem* rootItem = _dockWidget->getRootItem();
|
||||||
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
|
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
|
||||||
|
// The qmlToScript method handles the thread-safety of this call. Because the QVariant argument
|
||||||
|
// passed to the sendToScript signal may wrap an externally managed and thread-unsafe QJSValue,
|
||||||
|
// qmlToScript needs to be called directly, so the QJSValue can be immediately converted to a plain QVariant.
|
||||||
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)),
|
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)),
|
||||||
Qt::QueuedConnection);
|
Qt::DirectConnection);
|
||||||
QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
QObject::connect(rootItem, SIGNAL(keyReleaseEvent(int, int)), this, SLOT(forwardKeyReleaseEvent(int, int)),
|
QObject::connect(rootItem, SIGNAL(keyReleaseEvent(int, int)), this, SLOT(forwardKeyReleaseEvent(int, int)),
|
||||||
|
@ -229,7 +232,10 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
object->setProperty(VISIBLE_PROPERTY, properties[INTERACTIVE_WINDOW_VISIBLE_PROPERTY].toBool());
|
object->setProperty(VISIBLE_PROPERTY, properties[INTERACTIVE_WINDOW_VISIBLE_PROPERTY].toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(object, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
|
// The qmlToScript method handles the thread-safety of this call. Because the QVariant argument
|
||||||
|
// passed to the sendToScript signal may wrap an externally managed and thread-unsafe QJSValue,
|
||||||
|
// qmlToScript needs to be called directly, so the QJSValue can be immediately converted to a plain QVariant.
|
||||||
|
connect(object, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::DirectConnection);
|
||||||
QObject::connect(object, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
QObject::connect(object, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
QObject::connect(object, SIGNAL(keyReleaseEvent(int, int)), this, SLOT(forwardKeyReleaseEvent(int, int)),
|
QObject::connect(object, SIGNAL(keyReleaseEvent(int, int)), this, SLOT(forwardKeyReleaseEvent(int, int)),
|
||||||
|
@ -315,13 +321,21 @@ void InteractiveWindow::raise() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractiveWindow::qmlToScript(const QVariant& message) {
|
void InteractiveWindow::qmlToScript(const QVariant& originalMessage) {
|
||||||
|
QVariant message = originalMessage;
|
||||||
if (message.canConvert<QJSValue>()) {
|
if (message.canConvert<QJSValue>()) {
|
||||||
emit fromQml(qvariant_cast<QJSValue>(message).toVariant());
|
message = qvariant_cast<QJSValue>(message).toVariant();
|
||||||
} else if (message.canConvert<QString>()) {
|
} else if (message.canConvert<QString>()) {
|
||||||
emit fromQml(message.toString());
|
message = message.toString();
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Unsupported message type " << message;
|
qWarning() << "Unsupported message type " << message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread() != QThread::currentThread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "fromQml", Q_ARG(const QVariant&, message));
|
||||||
|
} else {
|
||||||
|
emit fromQml(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue