Results 1 to 2 of 2

Thread: QProcess Bash in Event Filter (Multiple Processes)

  1. #1
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation 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.

    Qt Code:
    1. m_Logw << new LogWindow;
    2. m_Logw[0]->installEventFilter(this);
    3. m_Logw[0]->setLineWrapMode(QTextEdit::WidgetWidth);
    4. m_Bash << new QProcess;
    5. m_Bash[0]->setReadChannelMode(QProcess::SeparateChannels);
    6. connect (m_Bash[0], SIGNAL(readyReadStandardOutput()),
    7. this, SLOT(showOutput()));
    8. m_Bash[0]->start("bash", QStringList("-i"), QIODevice::ReadWrite);
    9.  
    10.  
    11.  
    12. //.................. after constructor....................
    13.  
    14. bool Class::eventFilter(QObject *o, QEvent *e) {
    15. if (e->type() == QEvent::KeyPress) {
    16. QKeyEvent *k = static_cast<QKeyEvent*> (e);
    17. int key = k->key();
    18. QString str = k->text();
    19. m_UserInput[m_Tabs->currentIndex()].append(str);
    20. updateCursor();
    21. if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) ) {
    22. execute();
    23. return true; /* We processed the event. This
    24.   prevents other widgets from seeing it. */
    25. } else if(key == Qt::Key_Backspace){
    26. m_UserInput[m_Tabs->currentIndex()].chop(2); // chop the ending character and last character
    27. QString temp = m_Logw[m_Tabs->currentIndex()]->toPlainText();
    28. temp.chop(1); // remove the last character from the console window
    29. m_Logw[m_Tabs->currentIndex()]->setPlainText(temp); // reset it to the new version
    30. updateCursor(); // update cursor to go to end of screen
    31. return true;
    32. } else {
    33. m_Logw[m_Tabs->currentIndex()]->insertPlainText(str);
    34.  
    35. return true;
    36. }
    37. }
    38. return QMainWindow::eventFilter(o, e); /* Let the
    39.   base class eventFilter have a shot at it. */
    40. }
    41.  
    42. void Class::showOutput() {
    43. QByteArray bytes = m_Bash[m_Tabs->currentIndex()]->readAllStandardOutput();
    44. m_Logw[m_Tabs->currentIndex()]->append(QString(bytes));
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Arsenic; 8th November 2008 at 04:56.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

Tags for this Thread

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.