姬長信(Redy)

c – QThread发出finished()信号,但isRunning()返…


下面是我的qthread实现的代码.我试图从卫星获取gps数据.即使程序退出gpsSearch()槽功能,QThread也不会产生finished()信号.只要单击一个按钮,就会调用locateMe()函数.第一次没有启动线程并单击该按钮时,它会为isRunning()函数输出true值,并为isFinished()函数输出false值.我不得不调用QTherad的quit()函数来手动停止线程.之后,它转到gnssProvider类中连接的threadQuit()函数.但即便如此,如果我点击按钮,它会为isRunning输出真值,并为locateMe()函数中的isFinished()打印false.
GPSInfo::GPSInfo()
{
    hybridGPSFound = satelliteGPSFound = networkGPSFound = false;
    qDebug()moveToThread(gnssThread);
    connect(gnssThread, SIGNAL(started()), gnssProvider, SLOT(gpsSearch()));
    connect(gnssThread, SIGNAL(finished()), gnssProvider, SLOT(threadQuit()));
}
void LocationFetcher::gpsSearch()
{
    if (BPS_SUCCESS != geolocation_request_events(0))
    {
       fprintf(stderr, "Error requesting geolocation events: %s", strerror(errno));
       return;
    }
    geolocation_set_provider(GPS_Search_Provider);
    geolocation_set_period(GPS_Search_Period);
    while (!stopThread)
    {
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event)
        {
            if (bps_event_get_domain(event) == geolocation_get_domain() && bps_event_get_code(event) == GEOLOCATION_INFO)
            {
                handle_geolocation_response(event);
                break;
            }
        }
    }
    geolocation_stop_events(0);

    this->quit();

}
void GPSInfo::LocateMe()
{
    qDebug()isFinished();
    qDebug()isRunning();

    gnssThread->start();
    hybridThread->start();
    networkThread->start();

 }