主题 : 一个简单的线程例子编译编译通不过 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 9088
精华: 0
发帖: 62
金钱: 380 两
威望: 118 点
综合积分: 124 分
注册时间: 2009-09-16
最后登录: 2017-09-13
楼主  发表于: 2010-04-18 13:22

 一个简单的线程例子编译编译通不过

例子如下:实现的功能:开两个线程,每个都写ping!20次,然后退出.
#include <qthread.h>
#include <qapplication.h>
#include <stdio.h>
#include <stdlib.h>
class MyThread : public QThread {
  public:
    virtual void run();
  };
  void MyThread::run()
  {
    for(int count=0;count<20;count++) {
      sleep(1);
      qDebug("Ping!");
    }
  }
  int main()
  {
      MyThread a;
      MyThread b;
      a.start();
      b.start();
      a.wait();
      b.wait();
  }
先设置环境变量,然后运行qmake -project,然后用build脚本编译,脚本内如如下:
#!/bin/bash

source /opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv
qmake -o Makefile -spec /opt/FriendlyARM/mini2440/x86-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-generic-g++ *.pro

make clean
make
出错:
thread.h:6: error: expected class-name before ‘{’ token
thread.h: In member function ‘virtual void MyThread::run()’:
thread.h:17: error: ‘sleep’ was not declared in this scope
main.cpp: In function ‘int main()’:
main.cpp:10: error: ‘class MyThread’ has no member named ‘start’
main.cpp:11: error: ‘class MyThread’ has no member named ‘start’
main.cpp:12: error: ‘class MyThread’ has no member named ‘wait’
main.cpp:13: error: ‘class MyThread’ has no member named ‘wait’
make: *** [.obj/release-shared/main.o] Error 1
请高手指点迷津,在线等
级别: 新手上路
UID: 9123
精华: 0
发帖: 19
金钱: 135 两
威望: 45 点
综合积分: 38 分
注册时间: 2009-09-17
最后登录: 2010-11-12
1楼  发表于: 2010-04-21 13:50
我也碰到同样的问题。请高手指点啊!
级别: 侠客
UID: 5706
精华: 0
发帖: 119
金钱: 780 两
威望: 406 点
综合积分: 238 分
注册时间: 2009-05-05
最后登录: 2011-05-22
2楼  发表于: 2010-04-21 17:20
我觉得编译器已经提示了很明显了。