Hi Ralf,

I don't know the answer on your question, however...

If you're looking for some way of running long task in a background (for
not blocking main loop) then you might want to consider using Qt Concurrent.
Here's what I'm doing for my long tasks through Qt Concurrent:

// Initializes watching for async operation results
// Watcher might be a member of the current class (in UI it should be Model
class)
QFutureWatcher watcher = new QFutureWatcher();
watcher.finished.connect(this, "onFinished()");

// Forces method execution of rmethod run() in the background
future = QtConcurrent.run(this, this.getClass().getMethod("run"));
if (future != null) watcher.setFuture(future);

// According to watcher initialization, this method will be called when
execution will be done
// Results of execution might be retrieved by calling watcher.result()
private void onFinished() {
}

Qt Concurrent has some known advantages compared to raw threads.
Sorry if I'm off topic.

On Wed, Jun 20, 2012 at 9:30 AM, Ralf Van Bogaert <ralf.vanboga...@gmail.com
> wrote:

> Hi,
>
> I would like to implement threading in my program. In fact I have it up
> and running.
>
> However I would like to execute some code in the main event loop when the
> thread ends. The QThread class has a finished signal so I would like to use
> that.
>
> The problem is this signal is never triggered. I assume this would happen
> when the run() method reached the end.
>
> My code is:
>
> public class ThreadTest implements Runnable{
>
>     @Override
>     public void run() {
>
>         for(int A=0;A<10000;A++){
>
>             System.out.println(A);
>         }
>
>     }
> }
>
> ...
>
>
> ThreadTest test=new ThreadTest();
> QThread runner = new QThread(test);
> runner.starting.connect(this, "testStart()");
> runner.finished.connect(this, "testStop()");
>
> runner.start();
>
> The testStart() method is called correctly, however the testStop() method
> isn't.
>
> So do I need to finish the thread myself?
>
> If so, how?
>
> Regards
>
> Ralf
>
>
>
>
>
>
>
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest@qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
>
>


-- 

Vladimir Sapronov
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest

Reply via email to