Consumer.cpp
void Consumer::run()
{
j=0;
while(!flag_stop)
{
usedBytes.acquire();
write_str += buffer[j % 8096];
j++;
freeBytes.release();
emit disp(); // disp a slot of mainwindow.cpp
}
flag_stop = true;
}
Producer.cpp
void Producer::run()
{
i=0;
while(!flag_stop)
{
if(flag_read)
{
freeBytes.acquire();
int n = read_str.size();
buffer[i % 8096] = (*((read_str.toUtf8().constData())+(n-1)));
i++;
usedBytes.release();
flag_read = false;
}
}
flag_stop = true;
}
Mainwindow.cpp
...
connect(textEdit_1,SIGNAL(textChanged()),this,SLOT(read_send()));
connect(pushButton_14,SIGNAL(clicked()),this,SLOT(Start_Thread()));
connect(pushButton_15,SIGNAL(clicked()),this,SLOT(Stop_Thread()));
consumer = new Consumer();
producer = new Producer();
connect(consumer,SIGNAL(disp()),this,SLOT(receive_write()));
...
void MainWindowImpl::Start_Thread()
{
producer->start();
consumer->start();
}
void MainWindowImpl::Stop_Thread()
{
flag_stop = true;
}
void MainWindowImpl::read_send()
{
read_str = textEdit_1->toPlainText();
flag_read = true;
}
void MainWindowImpl::receive_write()
{
textEdit_2->setText(write_str);
}
{
flag_stop = true;
event->accept();
}
Consumer.cpp
void Consumer::run()
{
j=0;
while(!flag_stop)
{
usedBytes.acquire();
write_str += buffer[j % 8096];
j++;
freeBytes.release();
emit disp(); // disp a slot of mainwindow.cpp
}
flag_stop = true;
}
Producer.cpp
void Producer::run()
{
i=0;
while(!flag_stop)
{
if(flag_read)
{
freeBytes.acquire();
int n = read_str.size();
buffer[i % 8096] = (*((read_str.toUtf8().constData())+(n-1)));
i++;
usedBytes.release();
flag_read = false;
}
}
flag_stop = true;
}
Mainwindow.cpp
...
connect(textEdit_1,SIGNAL(textChanged()),this,SLOT(read_send()));
connect(pushButton_14,SIGNAL(clicked()),this,SLOT(Start_Thread()));
connect(pushButton_15,SIGNAL(clicked()),this,SLOT(Stop_Thread()));
consumer = new Consumer();
producer = new Producer();
connect(consumer,SIGNAL(disp()),this,SLOT(receive_write()));
...
void MainWindowImpl::Start_Thread()
{
producer->start();
consumer->start();
}
void MainWindowImpl::Stop_Thread()
{
flag_stop = true;
}
void MainWindowImpl::read_send()
{
read_str = textEdit_1->toPlainText();
flag_read = true;
}
void MainWindowImpl::receive_write()
{
textEdit_2->setText(write_str);
}
void MainWindowImpl::closeEvent(QCloseEvent *event)
{
flag_stop = true;
event->accept();
}
To copy to clipboard, switch view to plain text mode
Can any1 please help me that where i am misleading and where i have taken wrong approach.
Bookmarks