我希望这个问题有意义,我正在使用QTermWidget在Qt Creator 2.4.1中创建一个QTermWidget实例,如图here所示。我能够运行它并向嵌入式终端发送命令没有问题,但是,我希望能够向终端发送命令,等待终端完成,然后发送其他命令,如下所示:
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDir>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tabWidget->setUsesScrollButtons(true);
QIcon::setThemeName("oxygen");
this->setWindowIcon(QIcon::fromTheme("utilities-terminal"));
console = new QTermWidget();
QFont font = QApplication::font();
font.setFamily("Monospace");
font.setPointSize(12);
console->setTerminalFont(font);
console->setScrollBarPosition(QTermWidget::ScrollBarRight);
console->setColorScheme("WhiteOnBlack");
ui->tabWidget->insertTab(ui->tabWidget->currentIndex(), console,
QString(QDir::currentPath()));
QString Home = "ls";
QString enter = "\r";
console->sendText(Home);
// I would like the terminal to finish the previous command,
// before sending the next one, right now it just proceeds to
// the next line of code before it finishes.
console->sendText(enter);
console->sendText(QString cd);
console->sendText(enter);
}
MainWindow::~MainWindow()
{
delete ui;
}
提前致谢!