- 论坛徽章:
- 0
|
- #include "shelldemo.h"
- #include <QLineEdit>
- #include <QTextBlock>
- #include <QDebug>
- #include <QPlainTextEdit>
- //#include <private/qplaintextedit_p.h> //无法找到
-
- #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
- #include <private/v8.h>
- #endif
-
- ShellDemo::ShellDemo(QWidget *parent) :
- QPlainTextEdit(parent)
- {
- setReadOnly(true);
-
- QFont font = this->font();
- font.setPointSize(font.pointSize()+2);
- this->setFont(font);
-
- appendPlainText(">>> ");
- edit = new QLineEdit(this->viewport());
- edit->setStyleSheet("border-style:none; background-color:transparent;");
-
- connect(edit, SIGNAL(returnPressed()), SLOT(onEditFinished()));
- //connect(verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(onScrollBarValueChanged()));
- }
-
- void ShellDemo::resizeEvent(QResizeEvent *e)
- {
- updateEditPosition();
- }
-
- void ShellDemo::onScrollBarValueChanged()
- {
- updateEditPosition();
- }
-
- QString ShellDemo::runCommand(const QString &cmd)
- {
- return QString("Result of %1").arg(cmd);
- }
-
- void ShellDemo::onEditFinished()
- {
- QString cmd = edit->text();
- if (cmd.isEmpty()) {
- return;
- }
- moveCursor(QTextCursor::End);
- insertPlainText(cmd);
- //edit->hide();
- edit->clear();
-
- appendPlainText(runCommand(cmd));
-
- appendPlainText(">>> ");
- updateEditPosition();
- edit->show();
- edit->setFocus();
- }
-
- void ShellDemo::updateEditPosition()
- {
- QPlainTextEditPrivate *d = reinterpret_cast<QPlainTextEditPrivate*>(qGetPtrHelper(d_ptr));
-
- //QRectF rect = d->control->blockBoundingRect(d->control->document()->lastBlock()); //无法通过编译
- //edit->move(rect.topRight().toPoint());
- //edit->resize(viewport()->size().width(), edit->size().height());
- }
复制代码 按照 http://blog.csdn.net/dbzhang800/article/details/6751775 的方法在qt4.85环境下无法编译通过
报错信息是
错误1 找不到#include <private/qplaintextedit_p.h>
错误2 invalid use of undefined type ‘struct QPlainTextEditPrivate’
/usr/local/Trolltech/Qt-4.8.5/include/QtGui/qplaintextedit.h:65: 错误:forward declaration of ‘struct QPlainTextEditPrivate’
就是出在 QRectF rect = d->control->blockBoundingRect(d->control->document()->lastBlock()) 这一句
好像私有类不能这么用
求高人解释 急求! |
|