void SerialPortHandler::createSerialPortCommunicator() { try{ this->serial = new LagTestSerialPortComm( this->port, 115200, this->tm, this->clock_storage, this->adc_storage ); // Setup period query for arduino clock this->timer = new QTimer(this); connect(timer, SIGNAL(timeout()), serial, SLOT(sendClockRequest())); timer->setInterval(requestPeriod); this->thread = new QThread(); serial->moveToThread(thread); connect(thread, SIGNAL(started()), serial, SLOT(startCommunication())); connect(serial, SIGNAL(finished()), this, SLOT(onThreadQuit())); connect(serial, SIGNAL(finished()), serial, SLOT(deleteLater())); //Forward signals connect(serial, SIGNAL(sendDebugMsg(QString)), this, SIGNAL(sendDebugMsg(QString)) ); connect(serial, SIGNAL(sendErrorMsg(QString)), this, SIGNAL(sendErrorMsg(QString)) ); connect(serial, SIGNAL(sendFirmwareVersion(int)), this, SIGNAL(sendFirmwareVersion(int)) ); connect(serial, SIGNAL(sendArduinoTimeout()), this, SIGNAL(sendArduinoTimeout()) ); connect(serial, SIGNAL(sendArduinoDetectionFailed()), this, SIGNAL(sendArduinoDetectionFailed()) ); //This is not working, dont know why, cant get signal through to the slot // connect(this, SIGNAL(sendVersionCheck()), serial, SLOT(doVersionCheck()) ); // connect(this, SIGNAL(sendVersionCheck()), serial, SLOT(doSomethingElse()) ); // connect(this, SIGNAL(sendVersionCheck()), qApp, SLOT(aboutQt())); } catch (exception &e){ //qCritical("Connecting to the lagtest serial board failed!"); this->sendErrorMsg("Connecting to the lagtest serial board failed!"); throw e; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->var = 0; //Start a thread and execute doProcessing() QThread* thread = new QThread(); workingThread* worker = new workingThread( &(this->var) ); worker->moveToThread(thread); //connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(thread, SIGNAL(started()), worker, SLOT(doProcessing())); connect(worker, SIGNAL(finished()), this, SLOT(onThreadQuit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); for(double d = 0;d < 10e6; d++); qDebug("Main: set var = 1"); this->var = 1; for(double d = 0;d < 10e6; d++); this->var = 2; qDebug("Main: set var = 2"); for(double d = 0;d < 10e6; d++); this->var = 3; qDebug("Main: set var = 3"); qDebug("Main finished ..."); }
void mainApp::start() { //Start a thread and execute doProcessing() QThread* thread = new QThread(); LagTestSerialPortComm* serial = new LagTestSerialPortComm( 115200 ); serial->moveToThread(thread); //connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(thread, SIGNAL(started()), serial, SLOT(startCommunication())); connect(serial, SIGNAL(finished()), this, SLOT(onThreadQuit())); connect(serial, SIGNAL(finished()), serial, SLOT(deleteLater())); //connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }