Hi
I was reading one example about threads(wish i know almost nothing about) and got carried away by the imagination

I have one dialog:

ubmsr.h
Qt Code:
  1. #ifndef UBMSR_H
  2. #define UBMSR_H
  3.  
  4. #include <QtGui/QDialog>
  5.  
  6. #include "senderThread.h"
  7.  
  8. namespace Ui
  9. {
  10. class UbmsrClass;
  11. }
  12.  
  13. class Ubmsr : public QDialog
  14. {
  15. Q_OBJECT
  16.  
  17. public:
  18. Ubmsr(QWidget *parent = 0);
  19. ~Ubmsr();
  20. private slots:
  21. void startOrStopSenderThread();
  22. private:
  23. Ui::UbmsrClass *ui;
  24. senderThread *sender;
  25. };
  26.  
  27. #endif // UBMSR_H
To copy to clipboard, switch view to plain text mode 

ubmsr.cpp
Qt Code:
  1. #include "ubmsr.h"
  2. #include "ui_ubmsr.h"
  3.  
  4. Ubmsr::Ubmsr(QWidget *parent)
  5. : QDialog(parent), ui(new Ui::UbmsrClass)
  6. {
  7. ui->setupUi(this);
  8. sender = new senderThread;
  9. sender->setMessage("Hello!");
  10. connect(ui->senderButton, SIGNAL(clicked()), this, SLOT(startOrStopSenderThread()));
  11. }
  12.  
  13. Ubmsr::~Ubmsr()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void Ubmsr::startOrStopSenderThread(){
  19. ui->senderButton->setText("asdasd");
  20. if (sender->isRunning()) {
  21. sender->stop();
  22. ui->senderButton->setText(tr("Start Sender"));
  23. ui->senderMsg->setEnabled(true);
  24. ui->senderPort->setEnabled(true);
  25. }else{
  26. sender->start();
  27. ui->senderButton->setText(tr("Stop Sender"));
  28. ui->senderMsg->setEnabled(false);
  29. ui->senderPort->setEnabled(false);
  30. }
  31. }
To copy to clipboard, switch view to plain text mode 

senderThread.h
Qt Code:
  1. #ifndef SENDERTHREAD_H
  2. #define SENDERTHREAD_H
  3.  
  4. #include <QThread>
  5.  
  6. class senderThread : public QThread
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. senderThread();
  12. void setMessage(const QString &message);
  13. void stop();
  14.  
  15. protected:
  16. void run();
  17.  
  18. private:
  19. volatile bool senderStopped;
  20. QString messageStr;
  21.  
  22. };
  23.  
  24. #endif
To copy to clipboard, switch view to plain text mode 

senderThread.cpp
Qt Code:
  1. #include <QtCore>
  2. #include <iostream>
  3.  
  4. #include "senderThread.h"
  5.  
  6. using namespace std;
  7.  
  8. senderThread::senderThread()
  9. {
  10. senderStopped = false;
  11. }
  12.  
  13. void senderThread::setMessage(const QString &message)
  14. {
  15. messageStr = message;
  16. }
  17.  
  18. void senderThread::run()
  19. {
  20. while (!senderStopped)
  21. cerr << qPrintable(messageStr);
  22. senderStopped = false;
  23. cerr << endl;}
  24.  
  25. void senderThread::stop()
  26. {
  27. senderStopped = true;
  28. }
To copy to clipboard, switch view to plain text mode 

I can start and stop the thread and change the button label.

Is it possible to access the objects in the ui from a member function in the thread class?!

The final idea is to have 2 diferent threads sending and reading from a local network and showin all in the dialog i created.

I already managed the network issue ... the problem is putting this all togheter

How can i do it?

Thanks