QProcess Bash in Event Filter (Multiple Processes)
Hi
I'm trying to build a Multi-Tab Bash program, so I can have a separate QProcess of Bash in multiple tabs, and add and delete tabs as I like.
But whenever I run my program, without the QLists and only one instance without the Tabs, it works fine. It DOESN'T work fine when I add in the QLists and stuff.
The error: the Bash doesn't show up in many of the terminals.
Code:
m_Logw << new LogWindow;
m_Logw[0]->installEventFilter(this);
m_Logw
[0]->setLineWrapMode
(QTextEdit::WidgetWidth);
m_Bash
[0]->setReadChannelMode
(QProcess::SeparateChannels);
connect (m_Bash[0], SIGNAL(readyReadStandardOutput()),
this, SLOT(showOutput()));
//.................. after constructor....................
if (e
->type
() == QEvent::KeyPress) { int key = k->key();
m_UserInput[m_Tabs->currentIndex()].append(str);
updateCursor();
if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) ) {
execute();
return true; /* We processed the event. This
prevents other widgets from seeing it. */
} else if(key == Qt::Key_Backspace){
m_UserInput[m_Tabs->currentIndex()].chop(2); // chop the ending character and last character
QString temp
= m_Logw
[m_Tabs
->currentIndex
()]->toPlainText
();
temp.chop(1); // remove the last character from the console window
m_Logw[m_Tabs->currentIndex()]->setPlainText(temp); // reset it to the new version
updateCursor(); // update cursor to go to end of screen
return true;
} else {
m_Logw[m_Tabs->currentIndex()]->insertPlainText(str);
return true;
}
}
base class eventFilter have a shot at it. */
}
void Class::showOutput() {
QByteArray bytes
= m_Bash
[m_Tabs
->currentIndex
()]->readAllStandardOutput
();
m_Logw
[m_Tabs
->currentIndex
()]->append
(QString(bytes
));
}
Re: QProcess Bash in Event Filter (Multiple Processes)
in the first few lines you add objects to lists and the access them via index [0]. you are aware that this only is correct if the list was empty before?
otherwise the appended(!) objects will be found at [size()-1].
I suggest you setup the objects first and then append them. This is a tiny bit faster and saves you the chance of getting the index wrong.
HTH