我把程序改成这样:
while(1)
{
//    QTimer::singleShot(3000, &w, SLOT(slot()))
      QTimer *timer = new QTimer( &w );
      QObject::connect( timer, SIGNAL(timeout()), &w, SLOT(slot()));
      timer->start( 2000, TRUE );
      timer->stop();
    
    a.processEvents();
}
    return 0;
}
程序就进不去slot函数,我把stop 注释掉的话,就会是一直不停执行slot函数,然后停两秒,再继续重复执行slot函数。我将创建QTimer对象的那行放到while外面,就又不执行slot函数了。哎,刚刚接触QT,所以有点摸不着头脑,麻烦高手指教。