LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 996|回复: 1

关于qthread的问题.

[复制链接]
发表于 2003-11-8 11:12:12 | 显示全部楼层 |阅读模式
我在qt下用线程,连参考文档里的例子也没编译通过,想问问还有别的这方面的资料吗?
也不知道是不是我的编译方法有问题.
用的例子如下:
//a.cpp
    class MyThread : public QThread {

    public:

        virtual void run();

    };

    void MyThread::run()
    {
        for( int count = 0; count < 20; count++ ) {
            sleep( 1 );
            qDebug( "ing!" );
        }
    }

    int main()
    {
        MyThread a;
        MyThread b;
        a.start();
        b.start();
        a.wait();
        b.wait();
    }
编译方法:
qmake -project
qmake
make
出现错误:
g++ -c -pipe -Wall -W -I/usr/include/fontconfig -I/usr/include/Xft2 -O2 -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions  -DQT_NO_DEBUG -I/usr/lib/qt-3.0.5/include -I/usr/lib/qt-3.0.5/mkspecs/default -o a.o a.cpp
a.cpp:1: parse error before `{' token
a.cpp:10: invalid use of undefined type `class MyThread'
a.cpp:1: forward declaration of `class MyThread'
a.cpp: In member function `void MyThread::run()':
a.cpp:12: `sleep' undeclared (first use this function)
a.cpp:12: (Each undeclared identifier is reported only once for each function
   it appears in.)
a.cpp:13: `qDebug' undeclared (first use this function)
a.cpp: In function `int main()':
a.cpp:19: aggregate `MyThread a' has incomplete type and cannot be defined
a.cpp:20: aggregate `MyThread b' has incomplete type and cannot be defined
a.cpp:26:1: warning: no newline at end of file
make: *** [a.o] Error 1
有哪位大侠知道什么原因吗?
发表于 2003-11-10 20:31:56 | 显示全部楼层
谁说没有例子?
$QTDIR/examples/thread下有呀
建议你自己写一个pro文件

good luck
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表