Fixed the AbstractListModel example

This commit is contained in:
Filippo Cucchetto 2015-01-26 19:11:50 +01:00
parent 9f3be669e7
commit 470b2647b8
4 changed files with 37 additions and 2 deletions

View File

@ -203,6 +203,14 @@ void dos_qvariant_create_double(void** vptr, double value)
*vptr = new QVariant(value);
}
void dos_qvariant_create_qabstractlistmodel(void** vptr, void* value)
{
auto qobject = reinterpret_cast<QObject*>(value);
auto variant = new QVariant();
variant->setValue<QObject*>(qobject);
*vptr = variant;
}
void dos_qvariant_isnull(void* vptr, bool& isNull)
{
auto variant = reinterpret_cast<QVariant*>(vptr);
@ -289,6 +297,13 @@ void dos_qvariant_setQObject(void* vptr, void* value)
variant->setValue<QObject*>(qobject);
}
void dos_qvariant_setQAbstractListModel(void* vptr, void* value)
{
auto variant = reinterpret_cast<QVariant*>(vptr);
auto qobject = reinterpret_cast<QObject*>(value);
variant->setValue<QObject*>(qobject);
}
void dos_qobject_create(void** vptr, void* dObjectPointer, DObjectCallback dObjectCallback)
{
auto dynamicQObject = new DynamicQObject();

View File

@ -53,6 +53,7 @@ extern "C"
void dos_qvariant_create_qvariant(void **vptr, void* value);
void dos_qvariant_create_float(void **vptr, float value);
void dos_qvariant_create_double(void **vptr, double value);
void dos_qvariant_create_qabstractlistmodel(void **vptr, void* value);
void dos_qvariant_toInt(void* vptr, int& value);
void dos_qvariant_setInt(void* vptr, int value);
void dos_qvariant_toBool(void* vptr, bool& value);
@ -64,6 +65,7 @@ extern "C"
void dos_qvariant_toString(void* vptr, CharPtr& ptr, int& size);
void dos_qvariant_setString(void* vptr, const char* value);
void dos_qvariant_setQObject(void* vptr, void* value);
void dos_qvariant_setQAbstractListModel(void* vptr, void* value);
void dos_qvariant_isnull(void *vptr, bool& isNull);
void dos_qvariant_delete(void *vptr);
void dos_qvariant_assign(void* vptr, void* other);

View File

@ -2,8 +2,26 @@ import NimQml
import macros
import typeinfo
type MyQAbstractListModel = ref object of QAbstractListModel
m_name: string
proc create(self: MyQAbstractListModel) =
var qAbstractListModel = self.QAbstractListModel
qAbstractListModel.create()
proc delete(self: MyQAbstractListModel) =
var qAbstractListModel = self.QAbstractListModel
qAbstractListModel.delete()
proc newMyQAbstractListModel(): MyQAbstractListModel =
new(result, delete)
result.create()
method rowCount(self: MyQAbstractListModel): cint =
return 103
proc mainProc() =
var myListModel = newQAbstractListModel()
var myListModel = newMyQAbstractListModel()
defer: myListModel.delete()
let rows = myListModel.rowCount
echo rows

View File

@ -42,4 +42,4 @@ type
QAbstractListModelObj = object of RootObj
data: RawQAbstractListModel
deleted: bool
QAbstractListModel = ref QAbstractListModelObj ## A QAbstractListModel
QAbstractListModel* = ref QAbstractListModelObj ## A QAbstractListModel