小韩老师:程序崩溃一般是内存分配不好造成的,打眼瞟一下这个
context->setContextProperty("templist" ,nullptr);
context->setContextProperty("templist" , QVariant::fromValue(temp));
每次循环都注册一次templist,感觉很不合理。要把templist看做一个容器,容器就好比一个仓库,你的内容就是仓库里的货,你每次来了一批新货你是先把仓库拆了,再为新货建立一个仓库。
把context->setContextProperty("templist" , QVariant::fromValue(temp));放到构造函数中,或者这个接收消息函数外初始化。 context->setContextProperty("templist" ,nullptr);函数删除,你每次就对指针指向的内容操作,消息增加新消息,删除旧消息