diff options
4 files changed, 36 insertions, 23 deletions
diff --git a/src/Authoring/Studio/Application/StudioApp.cpp b/src/Authoring/Studio/Application/StudioApp.cpp index 91b1ab92..a5328c13 100644 --- a/src/Authoring/Studio/Application/StudioApp.cpp +++ b/src/Authoring/Studio/Application/StudioApp.cpp @@ -1990,9 +1990,11 @@ QSize CStudioApp::getRenderableSize(const QString &renderableId) r.m_size = PresentationFile::readSize(path); } else { // QML stream QQmlApplicationEngine qmlEngine(path); - QQuickItem *item = qobject_cast<QQuickItem *>(qmlEngine.rootObjects().at(0)); - if (item) - r.m_size = QSize(qRound(item->width()), qRound(item->height())); + if (qmlEngine.rootObjects().size() > 0) { + QQuickItem *item = qobject_cast<QQuickItem *>(qmlEngine.rootObjects().at(0)); + if (item) + r.m_size = QSize(qRound(item->width()), qRound(item->height())); + } } } return r.m_size; diff --git a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp index 643b6690..1588a745 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectFileSystemModel.cpp @@ -440,19 +440,24 @@ void ProjectFileSystemModel::importUrl(QDir &targetDir, const QUrl &url) QObject *qmlRoot = nullptr; if (extension == QLatin1String("qml")) { qmlEngine.load(sourceFile); - const char *rootClassName = qmlEngine.rootObjects().at(0) - ->metaObject()->superClass()->className(); - - // the assumption here is that any qml that is not a behavior is a qml stream - if (strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0) { // not a behavior - qmlRoot = qmlEngine.rootObjects().at(0); - - // put the qml in the correct folder - if (targetDir.path().endsWith(QLatin1String("/scripts"))) { - const QString path(QStringLiteral("../qml streams")); - targetDir.mkpath(path); // create the folder if doesn't exist (i.e. old project) - targetDir.cd(path); + if (qmlEngine.rootObjects().size() > 0) { + const char *rootClassName = qmlEngine.rootObjects().at(0) + ->metaObject()->superClass()->className(); + // the assumption here is that any qml that is not a behavior is a qml stream + if (strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0) { // not a behavior + qmlRoot = qmlEngine.rootObjects().at(0); + // put the qml in the correct folder + if (targetDir.path().endsWith(QLatin1String("/scripts"))) { + const QString path(QStringLiteral("../qml streams")); + targetDir.mkpath(path); // create the folder if doesn't exist + targetDir.cd(path); + } } + } else { + // Invalid qml file, block import + g_StudioApp.GetDialogs()->DisplayKnownErrorDialog( + tr("Failed to parse '%1'\nAborting import.").arg(sourceFile)); + return; } } // Copy the file to target directory diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp index 72964c04..05c68ecd 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp @@ -372,9 +372,13 @@ bool ProjectView::isQmlStream(int row) const return false; QQmlApplicationEngine qmlEngine(filePath); - const char *rootClassName = qmlEngine.rootObjects().at(0) - ->metaObject()->superClass()->className(); - return strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0; + if (qmlEngine.rootObjects().size() > 0) { + const char *rootClassName = qmlEngine.rootObjects().at(0) + ->metaObject()->superClass()->className(); + return strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0; + } else { + return false; + } } bool ProjectView::isRefreshable(int row) const diff --git a/src/Authoring/Studio/Utils/ImportUtils.cpp b/src/Authoring/Studio/Utils/ImportUtils.cpp index 46ba9efa..2bb4807c 100644 --- a/src/Authoring/Studio/Utils/ImportUtils.cpp +++ b/src/Authoring/Studio/Utils/ImportUtils.cpp @@ -57,11 +57,13 @@ SObjectFileType ImportUtils::GetObjectFileTypeForFile(const CFilePath &inFile, } else if (theExtension.Compare(CDialogs::GetQmlFileExtension(), Q3DStudio::CString::ENDOFSTRING, false)) { QQmlApplicationEngine qmlEngine(inFile.absoluteFilePath()); - const char *rootClassName = qmlEngine.rootObjects().at(0) - ->metaObject()->superClass()->className(); - bool isQmlStream = strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0; - return isQmlStream ? SObjectFileType(OBJTYPE_QML_STREAM, DocumentEditorFileType::QmlStream) - : SObjectFileType(OBJTYPE_BEHAVIOR, DocumentEditorFileType::Behavior); + if (qmlEngine.rootObjects().size() > 0) { + const char *rootClassName = qmlEngine.rootObjects().at(0) + ->metaObject()->superClass()->className(); + bool isQmlStream = strcmp(rootClassName, "Q3DStudio::Q3DSQmlBehavior") != 0; + return isQmlStream ? SObjectFileType(OBJTYPE_QML_STREAM, DocumentEditorFileType::QmlStream) + : SObjectFileType(OBJTYPE_BEHAVIOR, DocumentEditorFileType::Behavior); + } // If qml file is invalid, it will be of unknown type } else if (CDialogs::IsFontFileExtension(theExtension)) { return SObjectFileType(OBJTYPE_TEXT, DocumentEditorFileType::Font); } else if (CDialogs::IsEffectFileExtension(theExtension)) { |