代码如下:
/--------------------------------------------
main.cpp
...
#include "thread.h"
class form : public QWidget
{
Q_OBJECT
public:
thread *hread;
public:
form(QWidget *parent =0)
:QWidget(parent)
{
setFixedSize(800, 600);
hread.strat();
...
}
};
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
form *pw = new form;
pw->show();
return a.exec();
}
/------------------------------------------------
thread.cpp
#include "thread.h"
void thread::run()
{
for(x = 0; 3 > x; x ++)
printf("xxx%d \n", x++);
}
/-------------------------------------------------
thread.h
#ifndef THREAD_H
#define THREAD_H
#include <QThread>
class thread : public QThread
{
Q_OBJECT
public:
int x;
protected:
void run();
};
#endif
/---------------------------------------------------
编译结果:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.4.3/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include -I. -I. -I. -o main.o main.cpp
main.cpp:58: 错误:ISO C++ 不允许声明无类型的 ‘thread’
main.cpp:58: 错误:expected ‘;’ before ‘*’ token
main.cpp: In constructor ‘player_images_form::player_images_form(QWidget*)’:
main.cpp:69: 错误:‘hread’ 在此作用域中尚未声明
make: *** [main.o] 错误 1
/---------------------------------------------------
问题:
在c++中,到底一个类怎么去调用另一个类?,不是编译出错就是没有调用线程.(抱歉,以前是学c的,c++使用还不到一个月)
qt中如何在主线程中启动一个次线程??
是不是不能在QWidget中启动两个线程?
想了一天都想不出来...
请帮帮我,谢谢...