diff options
| -rw-r--r-- | src/tools/rcc/rcc.cpp | 4 | ||||
| -rw-r--r-- | src/tools/uic/python/pythonwriteimports.cpp | 20 | ||||
| -rw-r--r-- | tests/auto/tools/uic/tst_uic.cpp | 6 |
3 files changed, 18 insertions, 12 deletions
diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 6317d13a351..3b10e741a39 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -1112,7 +1112,9 @@ bool RCCResourceLibrary::writeHeader() writeByteArray(QT_VERSION_STR); writeString("\n"); writeString("# WARNING! All changes made in this file will be lost!\n\n"); - writeString("from PySide6 import QtCore\n\n"); + writeString("from PySide"); + writeByteArray(QByteArray::number(QT_VERSION_MAJOR)); + writeString(" import QtCore\n\n"); break; case Binary: writeString("qres"); diff --git a/src/tools/uic/python/pythonwriteimports.cpp b/src/tools/uic/python/pythonwriteimports.cpp index ed832228413..6f4a4e6f4fe 100644 --- a/src/tools/uic/python/pythonwriteimports.cpp +++ b/src/tools/uic/python/pythonwriteimports.cpp @@ -38,11 +38,13 @@ QT_BEGIN_NAMESPACE -static const char *standardImports = -R"I(from PySide6.QtCore import * -from PySide6.QtGui import * -from PySide6.QtWidgets import * -)I"; +static QString standardImports() +{ + return QString::fromLatin1(R"I(from PySide%1.QtCore import * +from PySide%1.QtGui import * +from PySide%1.QtWidgets import * +)I").arg(QT_VERSION_MAJOR); +} // Change the name of a qrc file "dir/foo.qrc" file to the Python // module name "foo_rc" according to project conventions. @@ -67,7 +69,7 @@ WriteImports::WriteImports(Uic *uic) : m_uic(uic) void WriteImports::acceptUI(DomUI *node) { auto &output = m_uic->output(); - output << standardImports << '\n'; + output << standardImports() << '\n'; if (auto customWidgets = node->elementCustomWidgets()) { TreeWalker::acceptCustomWidgets(customWidgets); output << '\n'; @@ -113,17 +115,17 @@ void WriteImports::acceptCustomWidget(DomCustomWidget *node) return; // Exclude namespaced names (just to make tests pass). const QString &importModule = qtModuleOf(node); auto &output = m_uic->output(); - // For starting importing PySide6 modules + // For starting importing Qt for Python modules if (!importModule.isEmpty()) { output << "from "; if (importModule.startsWith(QLatin1String("Qt"))) - output << "PySide6."; + output << "PySide" << QT_VERSION_MAJOR << '.'; output << importModule; if (!className.isEmpty()) output << " import " << className << "\n\n"; } else { // When the elementHeader is not set, we know it's the continuation - // of a PySide6 import or a normal import of another module. + // of a Qt for Python import or a normal import of another module. if (!node->elementHeader() || node->elementHeader()->text().isEmpty()) { output << "import " << className << '\n'; } else { // When we do have elementHeader, we know it's a relative import. diff --git a/tests/auto/tools/uic/tst_uic.cpp b/tests/auto/tools/uic/tst_uic.cpp index 0a07948dc2f..b9ab71736e9 100644 --- a/tests/auto/tools/uic/tst_uic.cpp +++ b/tests/auto/tools/uic/tst_uic.cpp @@ -117,7 +117,7 @@ static QByteArray msgProcessStartFailed(const QString &command, const QString &w return result.toLocal8Bit(); } -// Locate Python and check whether PySide6 is installed +// Locate Python and check whether Qt for Python is installed static QString locatePython(QTemporaryDir &generatedDir) { QString python = QStandardPaths::findExecutable(QLatin1String("python")); @@ -128,7 +128,9 @@ static QString locatePython(QTemporaryDir &generatedDir) QFile importTestFile(generatedDir.filePath(QLatin1String("import_test.py"))); if (!importTestFile.open(QIODevice::WriteOnly| QIODevice::Text)) return QString(); - importTestFile.write("import PySide6.QtCore\n"); + importTestFile.write("import PySide"); + importTestFile.write(QByteArray::number(QT_VERSION_MAJOR)); + importTestFile.write(".QtCore\n"); importTestFile.close(); QProcess process; process.start(python, {importTestFile.fileName()}); |
