• 4528阅读
  • 0回复

QTimer问题 [复制链接]

上一主题 下一主题
离线ljw_725
 

只看楼主 倒序阅读 楼主  发表于: 2006-06-07
我想使用QTimer来模拟多线程,定时器到时执行监测网络数据的函数,如果有数据,停止定时器,进行相应处理,处理完毕(弹出对话框或者显示一些文字信息)在界面,然后再开启定时器,
现在启动起来定时器正常,但是一点触摸屏,定时运行的程序停掉,如果一直按者触摸屏,定时器就一直跑,好像刚开始一样,点一下,它跑一下
请问哪位高手知道为什么?
void Map::init()
{
time = QTime::currentTime(); // get current time
  internalTimer = new QTimer( this ); // create internal timer
  connect( internalTimer, SIGNAL(timeout()), this,SLOT(ReadCommMem()) );
  internalTimer->start( 3000 ); // emit signal every 0.5 seconds

  ...
}

int Map::ReadCommMem()
{
  internalTimer->stop();   //暂时停止定时器计时
  // ret = read(file, buf ); //读取接收共享内存

    int* tcpReadp;
    int shmid1;
    shmid1 = shmget(SHMKEY_RECEIVE_COMMMEM, 4, IPC_CREAT);
    if((tcpReadp = (int*)shmat(shmid1, NULL, 0))<0)
    {
          perror("shmat 0 error");
    internalTimer->start(100);
          return 0;
    }
   
    printf("tcpReadp = %d \n",*tcpReadp);

      //根据共享内存中的内容将消息分发给各个相应的对象处理……;
     
      if(*tcpReadp == 0)
      {
      textLabel1->setText("Some one is calling");
       
        textLabel1->update();
      }

      if(*tcpReadp == 1)
      {

        textLabel1->setText("Use want to Hang Up");
        textLabel1->update();
        //this->update();
      }
      else if(*tcpReadp == 2)
      {

        textLabel1->setText("You have new mail");
        textLabel1->update();
        //this->update();
      }
      else if(*tcpReadp == 3)
      {

 

    textLabel1->setText("Video Box ");
    textLabel1->update();

      }
      internalTimer->start(100);   //重新启动定时器
  }
}
[ 此贴被XChinux在2006-06-07 18:33重新编辑 ]
快速回复
限100 字节
 
上一个 下一个