
Originally Posted by
hashb
Hi tbscope,you mean the slot of the thread executed in the main thread ?
Thanks a lot for you explanation,
it was just a test in order to produce a loop
Do this with QTimer. Something like this :
#ifndef AAA_
#define AAA_
#include <QThread>
#include <QString>
#include <QDebug>
#include <QTimer>
{
Q_OBJECT
public:
myClass ()
{
connect(&timer,
SIGNAL(timeout()),
this, SLOT(onDoComm()));
}
void run() { exec(); }
void startComm() {timer.start(10);}
signals:
void startSignal();
public slots:
void onDoComm()
{
static long i=1;
qDebug()<<str;
};
private:
};
#endif
#ifndef AAA_
#define AAA_
#include <QThread>
#include <QString>
#include <QDebug>
#include <QTimer>
class myClass : public QThread
{
Q_OBJECT
public:
myClass ()
{
connect(&timer,
SIGNAL(timeout()),
this, SLOT(onDoComm()));
}
void run() { exec(); }
void startComm() {timer.start(10);}
signals:
void startSignal();
public slots:
void onDoComm()
{
static long i=1;
qDebug()<<str;
str=QString("%1%2").arg(i++);
};
private:
QString str;
QTimer timer;
};
#endif
To copy to clipboard, switch view to plain text mode
In this example onDoComm will be executed one time per 10 ms
Bookmarks