源码

首页 » 归档 » 源码 » c – QThread发出finished()信号,但isRunning()返…

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()<<"Thread Creating";
    gnssThread = new QThread;
    gnssProvider = new LocationFetcher(this,GEOLOCATION_PROVIDER_GNSS,1);
    gnssProvider->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()<<"Thread Running: "<isFinished();
    qDebug()<<"Thread Running: "<isRunning();

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

 }
(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/c-qthreadfachufinishedxinhaodanisrunningfan.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9月 26, 2019 at 10:09 下午

热评文章