QTranslator: Fix loading of meta catalogs from absolute .qm path
In case of QTranslator translator; translator.load("somedir/file.qm"); and file.qm being a meta catalog file, the sub-catalogs in somedir couldn't be located, unless "somedir" was set as second argument. Pick-to: 5.15 6.1 6.2 Fixes: QTBUG-95013 Change-Id: I06103244ce2ff9800c2c64cb0c17f9bc7ef0e8de Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
parent
841ce1f938
commit
85eaae36f6
@ -603,9 +603,14 @@ bool QTranslatorPrivate::do_load(const QString &realname, const QString &directo
|
||||
}
|
||||
}
|
||||
|
||||
if (ok && d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength, directory)) {
|
||||
d->filePath = realname;
|
||||
return true;
|
||||
if (ok) {
|
||||
const QString base_dir =
|
||||
!directory.isEmpty() ? directory : QFileInfo(realname).absolutePath();
|
||||
if (d->do_load(reinterpret_cast<const uchar *>(d->unmapPointer), d->unmapLength,
|
||||
base_dir)) {
|
||||
d->filePath = realname;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(QT_USE_MMAP)
|
||||
|
@ -48,6 +48,7 @@ protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void init();
|
||||
|
||||
void load_data();
|
||||
void load();
|
||||
@ -75,6 +76,10 @@ void tst_QTranslator::initTestCase()
|
||||
{
|
||||
dataDir = QEXTRACTTESTDATA(QStringLiteral("/tst_qtranslator"));
|
||||
QVERIFY2(!dataDir.isNull(), qPrintable("Could not extract test data"));
|
||||
}
|
||||
|
||||
void tst_QTranslator::init()
|
||||
{
|
||||
QVERIFY2(QDir::setCurrent(dataDir->path()),
|
||||
qPrintable("Could not chdir to " + dataDir->path()));
|
||||
}
|
||||
@ -355,6 +360,15 @@ void tst_QTranslator::dependencies()
|
||||
QVERIFY(!tor.isEmpty());
|
||||
QCOMPARE(tor.translate("QPushButton", "Hello world!"), QLatin1String("Hallo Welt!"));
|
||||
}
|
||||
|
||||
{
|
||||
// Test resolution of paths relative to main file
|
||||
const QString absoluteFile = QFileInfo("dependencies_la").absoluteFilePath();
|
||||
QDir::setCurrent(QDir::tempPath());
|
||||
QTranslator tor;
|
||||
QVERIFY(tor.load(absoluteFile));
|
||||
QVERIFY(!tor.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
struct TranslateThread : public QThread
|
||||
|
Loading…
Reference in New Issue
Block a user