如果我没有使用 QThread 的指针对象,为什么仍然需要 QThread deleteLater?
Why is QThread deleteLater still required if I am not using a pointer object of QThread?
class Controller : public QObject
{
Q_OBJECT
private:
Two objTwo;
QThread objQThread;
Controller();
public slots:
void mySlot(){}
};
Controller::Controller()
{
objTwo.moveToThread( &objQThread );
connect( &objTwo, &Two::emitThisSignal, this, &Controller::mySlot );
connect( &objQThread, &QThread::finished, &objQThread, &QThread::deleteLater );
objQThread.start();
}
这里QThread的对象不是指针,所以这里还需要用deleteLater
吗?
在那里使用 class 对象而不是指针是否合适?
我认为这样可以防止删除。
Here the QThread's object is not a pointer, so will it still be required to use deleteLater
here?
没有
Is it appropriate to use class objects there instead of pointers?
总的来说,如果不需要,请不要使用指针。
I thought deletion can be prevented that way.
手动删除可以这样避免,是的。
class Controller : public QObject
{
Q_OBJECT
private:
Two objTwo;
QThread objQThread;
Controller();
public slots:
void mySlot(){}
};
Controller::Controller()
{
objTwo.moveToThread( &objQThread );
connect( &objTwo, &Two::emitThisSignal, this, &Controller::mySlot );
connect( &objQThread, &QThread::finished, &objQThread, &QThread::deleteLater );
objQThread.start();
}
这里QThread的对象不是指针,所以这里还需要用deleteLater
吗?
在那里使用 class 对象而不是指针是否合适?
我认为这样可以防止删除。
Here the QThread's object is not a pointer, so will it still be required to use
deleteLater
here?
没有
Is it appropriate to use class objects there instead of pointers?
总的来说,如果不需要,请不要使用指针。
I thought deletion can be prevented that way.
手动删除可以这样避免,是的。