kioslave: keep reference to the QByteArray object in CursorCreator::create()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-23 06:14:01 +03:00
parent 2c81ba5423
commit 24fa2781e2
2 changed files with 24 additions and 15 deletions

View file

@ -35,19 +35,28 @@ extern "C"
}
}
bool CursorCreator::create( const QString &path, int width, int height, QImage &img )
CursorCreator::CursorCreator()
{
XcursorImage *cursor = XcursorFilenameLoadImage(
QFile::encodeName( path ).data(),
width > height ? height : width );
}
if ( cursor ) {
img = QImage( reinterpret_cast<uchar *>( cursor->pixels ),
cursor->width, cursor->height, QImage::Format_ARGB32_Premultiplied );
bool CursorCreator::create(const QString &path, int width, int height, QImage &img)
{
const QByteArray pathbytes = QFile::encodeName(path);
XcursorImage *cursor = XcursorFilenameLoadImage(
pathbytes.constData(),
width > height ? height : width
);
if (cursor) {
img = QImage(
reinterpret_cast<uchar*>(cursor->pixels),
cursor->width, cursor->height,
QImage::Format_ARGB32_Premultiplied
);
// Create a deep copy of the image so the image data is preserved
img = img.copy();
XcursorImageDestroy( cursor );
XcursorImageDestroy(cursor);
return true;
}

View file

@ -17,17 +17,17 @@
Boston, MA 02110-1301, USA.
*/
#ifndef _CURSORCREATOR_H_
#define _CURSORCREATOR_H_
#ifndef CURSORCREATOR_H
#define CURSORCREATOR_H
#include <kio/thumbcreator.h>
class CursorCreator : public ThumbCreator
{
public:
CursorCreator() {}
bool create( const QString &path, int, int, QImage &img );
public:
CursorCreator();
bool create(const QString &path, int width, int height, QImage &img) final;
};
#endif
#endif // CURSORCREATOR_H