qt在子线程中启用定时器后无法关闭

it2026-04-20  5

这两句会在我删除我的对象的时候出现

udpChat = new UdpServer(); threadUdp = new QThread(this); udpChat->moveToThread(threadUdp); threadUdp->start(); delete udpChat;

QObject::killTimer: Timers cannot be stopped from another thread QObject::~QObject: Timers cannot be stopped from another thread

添加这两个槽后 即可

connect( threadUdp, SIGNAL(finished()), udpChat, SLOT(deleteLater()) ); connect( threadUdp, SIGNAL(finished()), threadUdp, SLOT(deleteLater()) );

参考来源:https://www.cnblogs.com/liushui-sky/p/5976979.html

最新回复(0)