Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, February 2007
Producer Consumer..


Message 1 in thread

Hi,

In my program I have a form and  2 edittext boxes (say e1 and e2) on it.

Now I want tht when I write on e1 then the thread1 shd start and write
the content in a buffer( byte array) and thread2 read  the buffer only
if its written by thread1 and write it to e2.

So now I cant access widgets fm thread classes so I need to transfer
data to and fro the producer consumer classes to form class too so as to
write on it.

So I want to ask tht when to start   when to wait the threads in this
case. This is same as semaphore example in the doc but I m trying to
implement in a diff manner and facing problem.

 

Producer::Producer(QObject *parent) : QThread(parent)

{  start();    wait();   }

 

void Producer::get_str(QString str)

{           s = str;  }  // public slots :    void get_str(QString str);

 

void Producer::run()

{           freeBytes.acquire();        usedBytes.release();     } //
where freebytes and usedbytes are Qsemaphore global var

 

Consumer::Consumer(QObject *parent) : QThread(parent)

{           start();               wait();   }

 

void Consumer::run()

{           usedBytes.acquire();         freeBytes.release();     }

 

 

Form1::Form1(QWidget *parent1):QWidget(parent1)

{   ui.setupUi(this);

    connect(ui.textEdit1,SIGNAL(textChanged()),this,SLOT(read_send()));

 
connect(ui.textEdit1,SIGNAL(textChanged()),this,SLOT(receive_write()));

}

 

void Form1::read_send()

{

QString str;       str = ui.textEdit1->toPlainText();
producer_object.get_str(str);               }

 

void Form1::receive_write()

{           ui.textEdit2->setText(s);             }

 

 

Regards, 
Shuchi

Project trainee 
IT Solutions & Services Engineering IT 
_________________________Honeywell
Honeywell Technology Solutions(HTS)