Qt/C++ Qt多线程竟然不能使用VC的套路

来源:互联网 发布:java实现aes256 编辑:程序博客网 时间:2024/05/22 12:33

Qt我创建如下代码,在VC下这类似的东西是没有问题的,Qt是不可以的~

class MainWindow : public QMainWindow{    Q_OBJECTpublic:    explicit MainWindow(QWidget *parent = 0);    ~MainWindow();/* * @brief:开始线程,这里是另线程的一起点*/    static unsigned int RunDecode(void *lparam);/* * @biref:线程是否在运行*/    bool IsThreadRunning();/* * @brief:解码*/    void Decode();//RunDecode的实现,里面调用了Decode方法,unsigned int MainWindow::RunDecode(void *lparam){    MainWindow *pWin=reinterpret_cast<MainWindow *>(lparam);    pWin->Decode();    return 1;}void MainWindow::Decode(){    /*如果这里调用了UI控件,编译链接不会出错,运行到这里就出错*/    /*error:Cannot send events to objects owned by a different thread. Current thread 17a8ee70. Receiver '' (of type 'QTextDocument') was created in thread 17a28090    它的意思是不能把QTextDocument的事件传到这个线程来,    经过测试,只要不调用UI控件就okay,些线程独立运行~*/}//难道只能规矩的使用Qt的多线程老套路?继承QThread,QtConcurrent,moveToThread?

更多文章:http://blog.csdn.net/what951006?viewmode=list
powered by:小乌龟在大乌龟背上~

原创粉丝点击