C#include <QtGui/QApplication>#include "mainwindow.h"#include "thread.h"#include <QTimer> //bool func();bool b;//QTimer t; void MyThread::run(){ QTimer t; //t = new QTimer(this); connect(&t,SIGNAL(timeout()),this,SLOT(func())); //t.start(10); exec();} int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; MyThread thread; thread.start(); if(thread.func() == true) int i=0; w.show(); return a.exec();}bool MyThread::func(){ bool b=true; return b;}
C#ifndef THREAD_H#define THREAD_H#include <QThread> class MyThread : public QThread { public: void run(); public slots: bool func();}; #endif // THREAD_H
C#include <QtGui/QApplication>#include "mainwindow.h"#include "thread.h"#include <QTimer> //bool func();bool b;QTimer t; void MyThread::run(){ //QTimer t; //t = new QTimer(this); connect(&t,SIGNAL(timeout()),this,SLOT(func())); t.start(10); exec();} int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; MyThread thread; thread.start(); if(b == true) int i=0; w.show(); return a.exec();}bool MyThread::func(){ bool b=true; return b;}
connect(&t,SIGNAL(timeout()),this,SLOT(func()), Qt::QueuedConnection);
if(b == true) int i=0;
C#include <QtGui/QApplication>#include "mainwindow.h"#include "thread.h"#include <QTimer> bool b = false;QTimer t; void MyThread::run(){ connect(&t,SIGNAL(timeout()),this,SLOT(func())); t.start(100); //func(); exec();} int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; MyThread thread; thread.start(); for(int i =0;i<1000000;i++) { int x = i*i*i*i*i*i; if(b == true) i=0; } w.show(); return a.exec();}bool MyThread::func(){ b = true; return b;}
debug/main.o: In function `MyThread':F:\QT\thread-build-desktop/../thread//thread.h:6: undefined reference to `vtable for MyThread'debug/main.o: In function `~MyThread':F:\QT\thread-build-desktop/../thread//thread.h:6: undefined reference to `vtable for MyThread'collect2: ld returned 1 exit status