I'm not touching GUI from thread.
Answer=Interface->Read();
if (Answer!=NULL)
{
char* tmp;
tmp=new char[Answer->Len*2+1];
convertByteTabToStr(Answer->Data, tmp, Answer->Len);
emit setTextQLineEdit(m_ui->AnsLineEdit, tmp);
emit appendQTextEdit
(m_ui
->LogTextEdit,
QString("Ans --> ") +tmp
);
delete[] tmp;
delete[] Answer->Data;
delete Answer;
}
else
{
emit setTextQLineEdit(m_ui->AnsLineEdit, "");
emit appendQTextEdit(m_ui->LogTextEdit, "Ans --> Can't read Ans.");
char Text[]="Can't read Ans.";
emit showMessageBox
(Text,
NULL,
QMessageBox::Critical);
}
Answer=Interface->Read();
if (Answer!=NULL)
{
char* tmp;
tmp=new char[Answer->Len*2+1];
convertByteTabToStr(Answer->Data, tmp, Answer->Len);
emit setTextQLineEdit(m_ui->AnsLineEdit, tmp);
emit appendQTextEdit(m_ui->LogTextEdit, QString("Ans --> ") +tmp);
delete[] tmp;
delete[] Answer->Data;
delete Answer;
}
else
{
emit setTextQLineEdit(m_ui->AnsLineEdit, "");
emit appendQTextEdit(m_ui->LogTextEdit, "Ans --> Can't read Ans.");
char Text[]="Can't read Ans.";
emit showMessageBox(Text, NULL, QMessageBox::Critical);
}
To copy to clipboard, switch view to plain text mode
I'm working with external device connected via RS232. I can't determine when the data will be came in, or how long I have to wait for answer (and answer length as well, simple I have to check when the data stop came in). From past I know that second thread is the best way (and the fasted too). Later I have to write another thread to listen on ethernet socket (it will be collect report from far away devices, and check the data). I can write data to file, and read the file in main thread then fill GUI widget, buy users don't like progress bars. They want to see how its going. Alternate method is function onIdle() (function that is calling when event queue is empty) and it's implemented in main thread (but it is not a really good idea). This is the reason why I chose the thread.
What about the first question?
Bookmarks