我有一个有很多方法的编码器类。这是 Qthread 的子类。我是多线程的新手
试图了解此类如何线程化其方法
...我理解线程必须在 qthread 的子类中的方法。并且 this 的运行实现了这个类的线程代码。并且该线程仅在调用此类对象的 start 方法时才启动。
问题: 首先你从这个运行实现中推断出什么
void Encoder::run(void)
{
VERBOSE(VB_DEBUG, "Encoder::run");
if (WILL_PRINT(VB_DEBUG))
print_stats_timer_id = QObject::startTimer(kEncoderDebugInterval);
health_check_timer_id = QObject::startTimer(kEncoderHealthCheckInterval);
if (init())
exec();
else
VERBOSE(VB_ERROR, "Encoder::run -- failed to initialize encoder");
QObject::killTimer(health_check_timer_id);
if (print_stats_timer_id)
QObject::killTimer(print_stats_timer_id);
cleanup();
}
问题:线程上下文相对于它的方法意味着什么。
还
问题:如果在这个类的线程开始之前调用这个类的一个方法会发生什么