• 3623阅读
  • 1回复

请问关于线程的问题 [复制链接]

上一主题 下一主题
离线wu9961
 

只看楼主 倒序阅读 楼主  发表于: 2008-07-13
— 本帖被 XChinux 执行加亮操作(2008-07-14) —
我创造了一个线程类
如下
#ifndef THREAD1_H_
#define THREAD1_H_
#include <iostream>
using namespace std;

class thread1:public QThread
{
    Q_OBJECT
public:
    thread1();
protected:
    void run();
};

#endif
#include "thread1.h"
#include "windows.h"

thread1::thread1()
{}
// place your code here
void thread1::run()
{
    QString text="A";
    while(true)
    {
        cout << qPrintable(text);
        Sleep(1);
    }
}
当我调用的时候 创建一个thread1的对象
thread1 t1;t1.start();之后出现了内存错误
当我这样创建的时候没有错误,请问这是为什么
thread1 *t1=new thread1();
t1->start();
第一种方法是在C++ GUI Programming with Qt4 Book 例程中看到的 不知道他的为什么就好用
请各位前辈点拨
离线lzian
只看该作者 1楼 发表于: 2008-07-14
我想可能是构造函数的问题,你可以把构造函数去掉。
如果不行,可以粘贴所有代码,研究
快速回复
限100 字节
 
上一个 下一个