c++ - 如何从 QPlainTextEdit 中读取特定行

标签 c++ qt

我有一个包含以下内容的 QPlainTextEdit:

This
is
a
QPlainTextEdit

我正在 Qt 文档中搜索要阅读的命令,例如第四行(QPlainTextEdit):比如readLine(int line),但是我找不到任何东西。

最佳答案

我会做以下事情:

QPlainTextEdit edit;
edit.setPlainText("This\nis\na\nQPlainTextEdit");

QTextDocument *doc = edit.document();
QTextBlock tb = doc->findBlockByLineNumber(1); // The second line.
QString s = tb.text(); // returns 'is'

关于c++ - 如何从 QPlainTextEdit 中读取特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21633206/

相关文章:

c++ - QTreeView 使用按钮移动项目

c++ - 防止 QGraphicsItem::itemAt() 在 "Background Item"

c++ - 我应该考虑网络字节顺序吗?

c++ - C 和 C++ 中内置数据类型的类型是什么?

c++ - 使用 bumblebee2 获取立体图像

c++ - 如何在 Qt 中使菜单项变灰

c++ - 保持数据迭代器的 vector

c++ - QtCreator C++ : 2D matrix gives different results in different member function of the same class

c++ - 使用 STL 算法在表( vector 的 vector ,二维数组)中查找最小值/最大值的优雅方法

c++ - Qt creator C++,void值没有被忽略,因为它应该被忽略