aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt3
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/cpptypes/hpp.hpp15
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/hpp.qml8
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp9
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h2
-rw-r--r--tools/qmltc/qmltcvisitor.cpp33
-rw-r--r--tools/qmltc/qmltcvisitor.h4
7 files changed, 52 insertions, 22 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
index 4c472ec4ab..a60330bc8e 100644
--- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
@@ -24,6 +24,7 @@ set(cpp_sources
cpptypes/typewithsignal.h
cpptypes/custominitialization.h
cpptypes/typewithrequiredproperties.h
+ cpptypes/hpp.hpp
)
set(qml_sources
@@ -137,6 +138,8 @@ set(qml_sources
badFile.qml
requiredProperties.qml
+
+ hpp.qml
)
set(js_sources
diff --git a/tests/auto/qml/qmltc/QmltcTests/cpptypes/hpp.hpp b/tests/auto/qml/qmltc/QmltcTests/cpptypes/hpp.hpp
new file mode 100644
index 0000000000..5ba60daba9
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/cpptypes/hpp.hpp
@@ -0,0 +1,15 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef HPP_HPP
+#define HPP_HPP
+
+#include <QtQml/qqml.h>
+
+class Hpp : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+};
+
+#endif // HPP_HPP
diff --git a/tests/auto/qml/qmltc/QmltcTests/hpp.qml b/tests/auto/qml/qmltc/QmltcTests/hpp.qml
new file mode 100644
index 0000000000..999e5eaf00
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/hpp.qml
@@ -0,0 +1,8 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QmltcTests 1.0
+
+Hpp {
+ objectName: "hpp"
+}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index ef33cebc00..6a7e6da201 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -92,6 +92,8 @@
#include "signalconnections.h"
#include "requiredproperties.h"
+#include "hpp.h"
+
// Qt:
#include <QtCore/qstring.h>
#include <QtCore/qbytearray.h>
@@ -3396,4 +3398,11 @@ void tst_qmltc::signalConnections()
QCOMPARE(createdByQmltc.objectName(), QLatin1String("second"));
}
+void tst_qmltc::hpp()
+{
+ QQmlEngine e;
+ PREPEND_NAMESPACE(hpp) createdByQmltc(&e);
+ QCOMPARE(createdByQmltc.objectName(), QLatin1String("hpp"));
+}
+
QTEST_MAIN(tst_qmltc)
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index ede6d551a0..926081f6d2 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -105,4 +105,6 @@ private slots:
#endif
void urlToString();
void signalConnections();
+
+ void hpp();
};
diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp
index a6ec1f8661..7eac98da0e 100644
--- a/tools/qmltc/qmltcvisitor.cpp
+++ b/tools/qmltc/qmltcvisitor.cpp
@@ -89,7 +89,7 @@ void QmltcVisitor::findCppIncludes()
return false;
};
const auto addCppInclude = [this](const QQmlJSScope::ConstPtr &type) {
- if (QString includeFile = type->filePath(); includeFile.endsWith(u".h"))
+ if (QString includeFile = filePath(type); !includeFile.isEmpty())
m_cppIncludes.insert(std::move(includeFile));
};
@@ -151,8 +151,8 @@ void QmltcVisitor::findCppIncludes()
for (const QQmlJSMetaProperty &p : properties) {
findInType(p.type());
- if (p.isPrivate() && t->filePath().endsWith(u".h")) {
- const QString ownersInclude = t->filePath();
+ if (p.isPrivate()) {
+ const QString ownersInclude = filePath(t);
QString privateInclude = constructPrivateInclude(ownersInclude);
if (!privateInclude.isEmpty())
m_cppIncludes.insert(std::move(privateInclude));
@@ -174,7 +174,7 @@ void QmltcVisitor::findCppIncludes()
}
// remove own include
- m_cppIncludes.remove(m_exportedRootScope->filePath());
+ m_cppIncludes.remove(filePath(m_exportedRootScope));
}
static void addCleanQmlTypeName(QStringList *names, const QQmlJSScope::ConstPtr &scope)
@@ -191,16 +191,9 @@ static void addCleanQmlTypeName(QStringList *names, const QQmlJSScope::ConstPtr
bool QmltcVisitor::visit(QQmlJS::AST::UiObjectDefinition *object)
{
- const bool processingRoot = !rootScopeIsValid();
-
if (!QQmlJSImportVisitor::visit(object))
return false;
- if (processingRoot || m_currentScope->isInlineComponent()) {
- Q_ASSERT(rootScopeIsValid());
- setRootFilePath();
- }
-
// we're not interested in non-QML scopes
if (m_currentScope->scopeType() != QQmlSA::ScopeType::QMLScope)
return true;
@@ -831,14 +824,14 @@ void QmltcVisitor::checkNamesAndTypes(const QQmlJSScope::ConstPtr &type)
}
/*! \internal
- * Sets the file paths for the document and the inline components roots.
+ * Returns the file path for the C++ header of \a scope or the header created
+ * by qmltc for it and its inline components.
*/
-void QmltcVisitor::setRootFilePath()
+QString QmltcVisitor::filePath(const QQmlJSScope::ConstPtr &scope) const
{
- const QString filePath = m_currentScope->filePath();
- if (filePath.endsWith(u".h")) // assume the correct path is set
- return;
- Q_ASSERT(filePath.endsWith(u".qml"_s));
+ const QString filePath = scope->filePath();
+ if (!filePath.endsWith(u".qml")) // assume the correct path is set
+ return scope->filePath();
const QString correctedFilePath = sourceDirectoryPath(filePath);
const QStringList paths = m_importer->resourceFileMapper()->resourcePaths(
@@ -850,13 +843,13 @@ void QmltcVisitor::setRootFilePath()
qCDebug(lcQmltcCompiler,
"Failed to find a header file name for path %s. Paths checked:\n%s",
correctedFilePath.toUtf8().constData(), matchedPaths.toUtf8().constData());
- return;
+ return QString();
}
// NB: get the file name to avoid prefixes
- m_currentScope->setFilePath(QFileInfo(*firstHeader).fileName());
+ return QFileInfo(*firstHeader).fileName();
}
-QString QmltcVisitor::sourceDirectoryPath(const QString &path)
+QString QmltcVisitor::sourceDirectoryPath(const QString &path) const
{
auto result = QQmlJSUtils::sourceDirectoryPath(m_importer, path);
if (const QString *srcDirPath = std::get_if<QString>(&result))
diff --git a/tools/qmltc/qmltcvisitor.h b/tools/qmltc/qmltcvisitor.h
index 111df0e885..b96c19063f 100644
--- a/tools/qmltc/qmltcvisitor.h
+++ b/tools/qmltc/qmltcvisitor.h
@@ -23,9 +23,9 @@ class QmltcVisitor : public QQmlJSImportVisitor
&qmlIrOrderedBindings);
void setupAliases();
void checkNamesAndTypes(const QQmlJSScope::ConstPtr &type);
- void setRootFilePath();
+ QString filePath(const QQmlJSScope::ConstPtr &scope) const;
- QString sourceDirectoryPath(const QString &path);
+ QString sourceDirectoryPath(const QString &path) const;
using InlineComponentOrDocumentRootName = QQmlJSScope::InlineComponentOrDocumentRootName;