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.
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
));
}
m_Logw << new LogWindow;
m_Logw[0]->installEventFilter(this);
m_Logw[0]->setLineWrapMode(QTextEdit::WidgetWidth);
m_Bash << new QProcess;
m_Bash[0]->setReadChannelMode(QProcess::SeparateChannels);
connect (m_Bash[0], SIGNAL(readyReadStandardOutput()),
this, SLOT(showOutput()));
m_Bash[0]->start("bash", QStringList("-i"), QIODevice::ReadWrite);
//.................. after constructor....................
bool Class::eventFilter(QObject *o, QEvent *e) {
if (e->type() == QEvent::KeyPress) {
QKeyEvent *k = static_cast<QKeyEvent*> (e);
int key = k->key();
QString str = k->text();
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;
}
}
return QMainWindow::eventFilter(o, e); /* Let the
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));
}
To copy to clipboard, switch view to plain text mode
Bookmarks