Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对象的某些属性或容器返回的地址与真实的地址不相符的问题 #47

Open
baagod opened this issue Sep 20, 2019 · 1 comment

Comments

@baagod
Copy link

baagod commented Sep 20, 2019

obj0 := qtcore.NewQObject(nil)
obj1 := qtcore.NewQObject(obj0)
obj2 := qtcore.NewQObject(obj0)

fmt.Println("obj0", obj0)
fmt.Println("obj1", obj1)
fmt.Println("obj2", obj2)
fmt.Println(obj1.Parent())
// obj1, obj2
fmt.Println(qtcore.NewQObjectListxFromPointer(obj0.Children().Cthis).ConvertToSlice())

result:

obj0 &{0xc0000aa068}
obj1 &{0xc0000aa080}
obj2 &{0xc0000aa098}
// 此处应该返回的是 obj0 的地址,但是和obj0本身的地址不一样。
&{0xc000010028}
// 此处应该返回 obj1, obj2 的地址,但是和它们本身的真实地址不一样。
[0xc0000aa0d0 0xc0000aa0f8]

返回的地址不一致会造成很多不方便的问题,比如判断两个对象是否相等,等等。这种情况能否解决?

@kitech
Copy link
Owner

kitech commented Sep 26, 2019

应该是封装方式造成的,用go struct封装了C++类型的指针,所以要想看到真实的指针需要多执行一步取地操作,obj.GetCthis()函数可以取到底层C++类型的指针。

在当时实现的时候曾考虑过另一种封装方式,直接使用unsafe.Pointer的别名,这样封装后的对象还是原来的C++指针。还没有测试过这种方式,不知道是否能实现现在所有的功能,只是为了保险选用了现在的struct封装方式。如果有兴趣多讨论一下,考虑一下,或者帮着试一试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants