C++ (Qt)Scanner scanner(this);scanner.scan() // получаем не блокирующий вызов, который выполняется в отдельном потоке и не тормозит основной.
C++ (Qt)class SomeClass : public QObject{ Q_OBJECTpublic: explicit SomeClass(QObject *parent = 0); signals: void workSignal(); public slots: void work(); void nonBlockWork(); };
C++ (Qt)SomeClass::SomeClass(QObject *parent) : QObject(parent){ connect(this, SIGNAL(workSignal()), this, SLOT(work()));} void SomeClass::work(){} void SomeClass::nonBlockWork(){ emit workSignal();}
QMetaObject::invokeMethod(someClass, "work", Qt::QueuedConnection);
bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoConnection ) [static]
C++ (Qt)myThread = new MyThread( this );connect ( ui->pushButton, SIGNAL( clicked() ), muThread, SLOT( doWork() ), Qt::QueuedConnection );myThread->start();
C++ (Qt)class CScaner: public QThread{public: CScaner( QObject * parent = 0):QThread(parent) { } void scan() { start(QThread::NormalPriority); }; //... protected: virtual void run() { reallyLongMethod(); emit image(/*...*/); }private: void reallyLongMethod() { // .... } }; CMyWidget::foo(){ CScaner* scaner = new CScaner(this); scaner->deleteLater(); connect(scaner, SIGNAL(image(/*...*/)), this, SLOT(setImageScan(/*....*/))); connect(scaner, SIGNAL(finished()), scaner, SLOT(deleteLater()); }