mirror of
https://github.com/gosticks/gml.git
synced 2025-10-16 12:05:33 +00:00
list model C new and free
This commit is contained in:
parent
9dfc3f684c
commit
898c132805
@ -45,6 +45,7 @@
|
|||||||
#include <QQuickTextureFactory>
|
#include <QQuickTextureFactory>
|
||||||
#include <QQuickAsyncImageProvider>
|
#include <QQuickAsyncImageProvider>
|
||||||
#include <QQuickImageResponse>
|
#include <QQuickImageResponse>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
|||||||
@ -32,12 +32,34 @@
|
|||||||
//#############//
|
//#############//
|
||||||
|
|
||||||
gml_list_model gml_list_model_new(void* go_ptr) {
|
gml_list_model gml_list_model_new(void* go_ptr) {
|
||||||
|
try {
|
||||||
|
GmlListModel* glm = new GmlListModel(go_ptr);
|
||||||
|
return (gml_list_model)glm;
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
gml_error_log_exception(e.what());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
gml_error_log_exception();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gml_list_model_free(gml_list_model lm) {
|
void gml_list_model_free(gml_list_model lm) {
|
||||||
if (lm == NULL) {
|
if (lm == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
GmlListModel* glm = (GmlListModel*)lm;
|
||||||
|
delete glm;
|
||||||
|
lm = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
//##########################//
|
||||||
|
//### GmlListModel Class ###//
|
||||||
|
//##########################//
|
||||||
|
|
||||||
|
GmlListModel::GmlListModel(
|
||||||
|
void* goPtr
|
||||||
|
) :
|
||||||
|
goPtr(goPtr) {}
|
||||||
|
|||||||
@ -30,4 +30,14 @@
|
|||||||
|
|
||||||
#include "gml_includes.h"
|
#include "gml_includes.h"
|
||||||
|
|
||||||
|
class GmlListModel : public QAbstractListModel {
|
||||||
|
public:
|
||||||
|
GmlListModel(
|
||||||
|
void* goPtr
|
||||||
|
);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* goPtr;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -40,6 +40,10 @@ import (
|
|||||||
type ListModelHandler interface {
|
type ListModelHandler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure the ListModel type implements the ListModelHandler interface.
|
||||||
|
|
||||||
|
var _ ListModelHandler = &ListModel{}
|
||||||
|
|
||||||
type ListModel struct {
|
type ListModel struct {
|
||||||
freed bool
|
freed bool
|
||||||
lm C.gml_list_model
|
lm C.gml_list_model
|
||||||
|
|||||||
@ -46,9 +46,9 @@ func Save(v interface{}) unsafe.Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate real fake C pointer.
|
// Generate real fake C pointer.
|
||||||
// This pointer will not store any data, but will bi used for indexing purposes.
|
// This pointer will not store any data, but will be used for indexing purposes.
|
||||||
// Since Go doest allow to cast dangling pointer to unsafe.Pointer, we do rally allocate one byte.
|
// Since Go does not allow to cast dangling pointer to unsafe.Pointer, we do really allocate one byte.
|
||||||
// Why we need indexing, because Go doest allow C code to store pointers to Go data.
|
// Why we need indexing, because Go does not allow C code to store pointers to Go data.
|
||||||
ptr := C.malloc(C.size_t(1))
|
ptr := C.malloc(C.size_t(1))
|
||||||
if ptr == nil {
|
if ptr == nil {
|
||||||
panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")
|
panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user