[Qt-interest] Basic Qthread question - part 4

Phil phillor at telstra.com
Wed May 5 10:07:18 CEST 2010


Once again, thank you for reading this.

I thought I had threads sorted out but apparently not.

First the GUI starts the thread timer, then each second getData() is called.  
getData() is time-intensive and still blocks the GUI while it is running.

I have tried QThread::quit() at the end of getData() in case I need to start a 
new thread each second but that is not the answer. Actually, I have tried just 
about everything that I can think of; all without success.

I must nearly have this correct, surely.
 
Timer::Timer(QObject *parent) : QThread(parent)
{
    timer_.setInterval(1000);

    connect(&timer_, SIGNAL(timeout()), this, SLOT(getData()));

    QThread::start();
}

Timer::~Timer()
{
}

void Timer::run()
{
    //should I have some useful code here? 
    exec();
}

void Timer::getData()
{
    // time-intensive operation here
    ........

    //display the data on the GUI	
    emit dataReady(list);
}

-- 
Regards,
Phil



More information about the Qt-interest-old mailing list