Results 1 to 2 of 2

Thread: Producer Consumer...

  1. #1
    Join Date
    Dec 2006
    Posts
    103
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Producer Consumer...

    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,SL OT(read_send()));
    connect(ui.textEdit1,SIGNAL(textChanged()),this,SL OT(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); }

    here i have yet not implemented the code of using buffer and all. wil do it later.
    I worked on windows Xp with Qt 4.2.2(Open Source Version) and MinGw
    now i am trying the same things on Fedora Core 5 (linux-gcc) and Qt 4.2.2 open source edition.

  2. #2
    Join Date
    Dec 2006
    Posts
    103
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Producer Consumer...

    i have solved my problem. So dont reply.
    thanks
    I worked on windows Xp with Qt 4.2.2(Open Source Version) and MinGw
    now i am trying the same things on Fedora Core 5 (linux-gcc) and Qt 4.2.2 open source edition.

Similar Threads

  1. Producer Consumer
    By ^NyAw^ in forum Qt Programming
    Replies: 16
    Last Post: 17th November 2006, 19:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.