Hi
I have tried to create thread.
my doubts are as below:
1.the way it is created is correct or not?
2.After adding signal Getting error in .h file Signal_FromQThread(QString) is protected and in .cpp giving error "within context" where signal is emitted.
3.the purpose of creating QThread is to do calculations in this thread and after passing control to main thread slot update() is called for paint.so that time it is taking now can be reduced.
pls refer below code
pls suggest on it
Thanks,
sanujas
//in thread.h
#include <qthread.h>
class Cthread : public QWidget, private Ui::CthreadBase
{
Q_OBJECT
//Qthread newly added
class CRefresher : public QThread
{
public:
static Cthread *m_fun;
signals:
void Signal_FromQThread(QString);
protected:
void run()
{
m_fun->updateThefun();
}
};
friend class CRefresher;
private slots:
void updatefun();
private:
void updateThefun();
}
//in thread.cpp
//in constructor
Cthread* Cthread::CRefresher::m_scopeGraph = NULL;
Cthread::Cthread( QWidget *l_Parent ) : QWidget( l_Parent )
{
updateThefun();
Cthread::CRefresher::m_fun = this;
m_TimerThread = new QTimer( this );
connect( m_TimerThread, SIGNAL( timeout() ), this,
SLOT( updatefun()) );
connect(Cthread::CRefresher::m_fun, SIGNAL(Signal_FromQThread(QString)), this, SLOT(update()), Qt::QueuedConnection);
m_TimerThread->start( 1000 );
}
//newly added function
void Cthread::updatefun()
{
Cthread::CRefresher l_refersher;
l_refersher.start();
l_refersher.setPriority(QThread::LowestPriority);
l_refersher.wait();
emit l_refersher.Signal_FromQThread("emitting thread signal");
}
//in function
void Cthread::updateThefun()
{
//some calculations
//....
//....
update();
}
void Cthread:aintEvent( QPaintEvent *f_ptrEvent)
{
//draw
//....
//....
}
Bookmarks