Derek Fountain wrote:
>> If you have a signal in your model:
>>
>>   QSignal0 modelChanged
>>
>> and you connect
>>
>>   modelChanged.connect(view, "update()");
>>
>> then when you do:
>>
>>   // update model in model thread
>>   modelChanged.emit();
>>
>> update() will be called on the view in the GUI thread. This is a queued 
>> connection. Actually it is an auto connection which decides to do the 
>> operation queued at run time because the emitter and receiver are in 
>> different threads.
>>
>> The connect statement can be performed from any thread.
> 
> OK, I think I understand this now. :) But it's still not working. 
> Firstly, is there a QSignal0 class? I've used QSignalEmitter.Signal0. Is 
> that what you meant, or have I missed something else? :)

Sorry, I meant QSignalEmitter.Signal0 ;)

> More importantly, I've used something similar to the code above, and 
> still get an exception. Inside my view class, which extends QWidget, 
> I've created a field called updateSignal which is a Signal0. From inside 
> my view class constructor I make the queued connection explicitly like this:
> 
>   this.updateSignal.connect(this, "update()",
>                             Qt.ConnectionType.QueuedConnection);
> 
> and from the thread started by the model's Timer, I do the emit like this:
> 
>   this.updateSignal.emit();

It makes more sense if the signal lives in the model thread:

import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.*;

public class QueuedConnection {

     private static class WorkerThread extends QSignalEmitter implements 
Runnable {
         public Signal1<Integer> timeout = new Signal1<Integer>();

         public WorkerThread() {
             new Thread(this).start();
         }

         public void run() {
             long startTime = System.currentTimeMillis();
             while (1 + 1 == 2) {
                 try { Thread.currentThread().sleep(1000); } catch 
(Exception e) { }
                 timeout.emit((int) (System.currentTimeMillis() - 
startTime));
             }
         }

     }

     public static void main(String args[]) {
         QApplication.initialize(args);

         WorkerThread thread = new WorkerThread();


         QLabel label = new QLabel();
         thread.timeout.connect(label, "setNum(int)");

         label.show();

         QApplication.exec();

     }
}
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to