[zeromq-dev] nzmqt question: how to stop?

Marco Trapanese marcotrapanese at gmail.com
Sat May 26 17:41:06 CEST 2012


Hello,

when my Qt application ends the zmq engine is still running.
The examples provided hasn't any destructor or stop method.

As far as I know the QRunnable class doesn't have a way to stop. So I 
tried to inherit QThread which has the quit slot.

In my application I use other QThread classes and there is no problem to 
terminate on exit.

Only the zmq class remains active.
Here my constructor:

explicit FemtoClient(QObject* parent) : QThread(parent) {
     m_address = "tcp://blablabla";
     ZMQContext* context = createDefaultContext(this);
     context->start();
     m_socket = context->createSocket(ZMQSocket::TYP_DEALER);
     connect(m_socket, SIGNAL(messageReceived(const QList<QByteArray> 
&)), this, SLOT(requestReceived(const QList<QByteArray> &)));
     timerout = new QTimer(this);
     timerout->setInterval(2500);
     timerout->setSingleShot(true);
     connect(timerout, SIGNAL(timeout()), this, SLOT(timerout_timeout()));
}

the run() and stop() slot:

void run() {
     m_socket->connectTo(m_serverAddr);
     timerout->start();
     this->exec();
}

void stop() {
     timerout->stop();
     m_socket->close();
     this->quit();
}

How to start zmq:

client = new FemtoClient(this);
client->start();

in the destructor I call:

client->stop();


What do you recommend to avoid this issue?

Thanks!
Marco




More information about the zeromq-dev mailing list