fixes qmovie breaking on error. (#370)
Adds default error handler for all event listeners
This commit is contained in:
parent
c74a890068
commit
0f4f0c5567
@ -2,7 +2,9 @@
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QPointer>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QObject/qobject_macro.h"
|
||||
@ -13,6 +15,7 @@ class DLL_EXPORT QMovieWrap : public Napi::ObjectWrap<QMovieWrap> {
|
||||
|
||||
private:
|
||||
QPointer<NMovie> instance;
|
||||
QSharedPointer<QBuffer> bufferDevice;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
@ -36,4 +39,5 @@ class DLL_EXPORT QMovieWrap : public Napi::ObjectWrap<QMovieWrap> {
|
||||
Napi::Value currentFrameNumber(const Napi::CallbackInfo& info);
|
||||
Napi::Value currentPixmap(const Napi::CallbackInfo& info);
|
||||
Napi::Value loadFromData(const Napi::CallbackInfo& info);
|
||||
Napi::Value frameCount(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
@ -28,6 +28,7 @@ Napi::Object QMovieWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("currentFrameNumber", &QMovieWrap::currentFrameNumber),
|
||||
InstanceMethod("currentPixmap", &QMovieWrap::currentPixmap),
|
||||
InstanceMethod("loadFromData", &QMovieWrap::loadFromData),
|
||||
InstanceMethod("frameCount", &QMovieWrap::frameCount),
|
||||
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QMovieWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -57,6 +58,7 @@ QMovieWrap::QMovieWrap(const Napi::CallbackInfo& info)
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
this->bufferDevice = QSharedPointer<QBuffer>(new QBuffer);
|
||||
this->rawData = extrautils::configureQObject(this->getInternalInstance());
|
||||
}
|
||||
|
||||
@ -167,8 +169,13 @@ Napi::Value QMovieWrap::loadFromData(const Napi::CallbackInfo& info) {
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Buffer<const char> buffer = info[0].As<Napi::Buffer<const char>>();
|
||||
QByteArray byteArray = QByteArray(buffer.Data(), buffer.Length());
|
||||
QBuffer* bufferDevice = new QBuffer();
|
||||
bufferDevice->setData(byteArray);
|
||||
this->instance->setDevice(bufferDevice);
|
||||
this->bufferDevice->setData(byteArray);
|
||||
this->instance->setDevice(bufferDevice.data());
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
Napi::Value QMovieWrap::frameCount(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
int frameCount = this->instance->frameCount();
|
||||
return Napi::Value::From(env, frameCount);
|
||||
}
|
||||
|
||||
@ -74,6 +74,9 @@ export class QMovie extends NodeObject<QMovieSignals> {
|
||||
currentPixmap(): QPixmap {
|
||||
return new QPixmap(this.native.currentPixmap());
|
||||
}
|
||||
frameCount(): number {
|
||||
return this.native.frameCount();
|
||||
}
|
||||
}
|
||||
|
||||
export enum CacheMode {
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { NativeElement, Component, NativeRawPointer } from './Component';
|
||||
|
||||
function addDefaultErrorHandler(native: NativeElement, emitter: EventEmitter): void {
|
||||
native.subscribeToQtEvent('error');
|
||||
emitter.addListener('error', () => null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
> Abstract class that adds event handling support to all widgets.
|
||||
@ -37,6 +42,7 @@ export abstract class EventWidget<Signals extends {}> extends Component {
|
||||
} else {
|
||||
throw new Error('initNodeEventEmitter not implemented on native side');
|
||||
}
|
||||
addDefaultErrorHandler(native, this.emitter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user