Exemplo n.º 1
0
/**
 * @brief MapManager::setupRobotManagerThread esegue il setup del thread su cui gira la parte di controllo del robot
 */
void MapManager::setupRobotManagerThread()
{
    //Creo l'istanza del thread secondario
//    QThread* robotManagerThread = new QThread(this);
    robotManagerThread = new QThread(this);

    // Sposto l'oggetto che controlla il robot nell'altro thread
    robotManager.moveToThread(robotManagerThread);

    //Connetto il signal che dichiara l'inizio dell'esecuzione del thread con lo slot che si occupa dell'inizializzazione della classe
    QObject::connect(robotManagerThread, SIGNAL(started()), &robotManager, SLOT(init()));

    // Connetto i signal della classe del robot a quelli della GUI, in modo da poterli usare da QML
    QObject::connect(&robotManager, SIGNAL(pointFound(QVariant,QVariant)), this, SIGNAL(pointFound(QVariant,QVariant)));
    QObject::connect(&robotManager, SIGNAL(victimFound(QVariant)), this, SIGNAL(victimFound(QVariant)));
    QObject::connect(&robotManager, SIGNAL(robotTurn(QVariant)), this, SIGNAL(robotTurn(QVariant)));
    QObject::connect(&robotManager, SIGNAL(generateStep()), this, SIGNAL(generateStep()));

    // Dato che uso signal che passano paremtri Mat di opencv, devo esplori al meta system delle Qt
    qRegisterMetaType< cv::Mat >("cv::Mat");

    // Connetto i signal che inviano immagini da mostrare ai rispettivi slot
    QObject::connect(&robotManager, SIGNAL(newCameraImage(cv::Mat)), this, SLOT(printImage(cv::Mat)));
    QObject::connect(&robotManager, SIGNAL(victimImageFound(cv::Mat)), this, SLOT(printVictimImage(cv::Mat)));

    // Segnalo di terminare il thread alla chiusura della GUI (anche se non sembra far nulla)
    QObject::connect(this, SIGNAL(destroyed()), robotManagerThread, SLOT(quit()));

    // Avvio il thread
    robotManagerThread->start();
}
Exemplo n.º 2
0
Canvas::Canvas(QWidget *parent): QWidget(parent){
  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  createLayout();
  model = new PointSet();
  reader = new PointXmlReader(this);
  writer = new PointXmlWritter(this);
  connect(reader, SIGNAL(pointFound(FloatPoint)), this, SLOT(addPoint(FloatPoint)));
  connect(reader, SIGNAL(readingSuccessful()), this, SLOT(redraw()));
  connect(reader, SIGNAL(readingError(QString)), this, SLOT(showErrorMsg(QString)));
  connect(writer, SIGNAL(writingSuccessful()), this, SLOT(redraw()));
  connect(writer, SIGNAL(writingError(QString)), this, SLOT(showErrorMsg(QString)));
  confidence = 0;
}