⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qonsole.cpp

📁 压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架>>所有源码
💻 CPP
字号:
#include "qonsole.h"#include <logwindow.h>#include <QDockWidget>#include <QLineEdit>#include <QProcess>#include <QByteArray>#include <QEvent>#include <QDebug>#include <QKeyEvent>#include <QTextCursor>//start id="constructor"Qonsole::Qonsole() {   m_Logw = new LogWindow("debug");   setCentralWidget(m_Logw);    m_Logw->installEventFilter(this);   m_Logw->setLineWrapMode(QTextEdit::WidgetWidth);   m_Bash = new QProcess();   m_Bash->setReadChannelMode(QProcess::MergedChannels);   connect (m_Bash, SIGNAL(readyReadStandardOutput()),             this, SLOT(showOutput()));   m_Bash->start("bash", QStringList("-i"), QIODevice::ReadWrite);             }//end//start id="event"bool Qonsole::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.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 {            m_Logw->insertPlainText(str);            return true;        }    }    return QMainWindow::eventFilter(o, e); /* Let the          base class eventFilter have a shot at it. */}//end    void Qonsole::showOutput() {    QByteArray bytes = m_Bash->readAllStandardOutput();    m_Logw->append(QString(bytes));}//start id="update-execute"void Qonsole::updateCursor() {    QTextCursor cur = m_Logw->textCursor();    cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);    m_Logw->setTextCursor(cur);}void Qonsole::execute() {    QByteArray bytes = m_UserInput.toUtf8();    m_Bash->write(bytes);    m_UserInput = "";    }//end#include <QApplication>int main(int argc, char* argv[]) {    QApplication app(argc, argv);    Qonsole qon;    qon.show();    return app.exec();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -