Hi,

I need to to manage serial port stream, and update my ui consequently.
Reading some post here in the forum I wrote the attached example zufolo.tar.gz, where the thread zotthread simulates serial port management.

here is the screenshot
screenshot.png

the application is very simple.

that are slots in dialog:
Qt Code:
  1. void Dialog::ovvaivai(void)
  2. {
  3. zotThread *zt;
  4.  
  5. zt = new zotThread;
  6.  
  7. connect(zt, SIGNAL(lancettasecondi(const QString&)), this, SLOT(cambiatestobottone(const QString&)));
  8. connect(zt, SIGNAL(uscita()), this, SLOT(chiusura()));
  9. zt->start();
  10. }
  11.  
  12. void Dialog::cambiatestobottone(const QString &s)
  13. {
  14. ui->pushButton->setText(s);
  15. }
  16.  
  17. void Dialog::chiusura(void)
  18. {
  19. close();
  20. }
To copy to clipboard, switch view to plain text mode 

and this is the thread taht simulates serial management
Qt Code:
  1. void zotThread::run(void)
  2. {
  3. int i;
  4. QTimer qt;
  5. for(i=5;i>0;i--)
  6. {
  7. s.setNum(i);
  8. emit lancettasecondi(s);
  9. qt.setSingleShot(true);
  10. qt.start(1000);
  11. while(qt.isActive()) QCoreApplication::processEvents();
  12. }
  13. emit uscita();
  14. }
To copy to clipboard, switch view to plain text mode 

when clicking the pushbutton ovvaivai(void) is called, so then thread starts. It perform a 5 seconds countdown before close the application.

I wonder if this is the right way to change the ui from a thread.
An also I wonder if is correct to call QCoreApplication::processEvents(); from inside trhead main loop. Without that call timer dosn't walk.

Now I want to read the spin value from thread. How can I perform that action? I don't think through signal/slot.

thanks