diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-06-21 17:32:32 -0700 |
|---|---|---|
| committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-07-02 21:15:04 -0700 |
| commit | 265ae27a3cc747affae26923ebaa3cc7c49477c1 (patch) | |
| tree | 229e8a682cebf6d196da7df968ba9b55c1f89654 /src/quick/items/qquicktextedit.cpp | |
| parent | ae76c8f428e9ca7ac5d398b51ffdb03407a26f04 (diff) | |
TextEdit: load inline images from resources the same as local files
QQuickTextEdit::loadResource() now loads resource images with QFile
rather than creating a QQuickPixmap "job". connectFinished() was
complaining, presumably because loading happens instantly, and we don't
need async notification when it gets done.
Fixes: QTBUG-125526
Pick-to: 6.7 6.8
Change-Id: Ibcea546104aefb35ee333dfd0ac13c07549e33c7
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextedit.cpp')
| -rw-r--r-- | src/quick/items/qquicktextedit.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 03e5c14ba1..04dd55237e 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -2325,6 +2325,23 @@ QVariant QQuickTextEdit::loadResource(int type, const QUrl &source) return {}; } + // If the image is in resources, load it here, because QTextDocument::loadResource() doesn't do that + if (!url.scheme().compare("qrc"_L1, Qt::CaseInsensitive)) { + // qmlWarning if the file doesn't exist + QFile f(QQmlFile::urlToLocalFileOrQrc(url)); + if (f.open(QFile::ReadOnly)) { + QByteArray buf = f.readAll(); + f.close(); + QImage image; + image.loadFromData(buf); + if (!image.isNull()) + return image; + } + // if we get here, loading failed + qmlWarning(this) << "Cannot read resource: " << f.fileName(); + return {}; + } + // see if we already started a load job auto existingJobIter = std::find_if( d->pixmapsInProgress.cbegin(), d->pixmapsInProgress.cend(), |
