通过 QTextStream 流式传输到 QTextEdit
我经常想使用 QTextEdit 作为显示正在编写的内容的快速方法 到一条溪流。也就是说,我想要的不是写入 QTextStream out(stdout) 做类似的事情:
QTextEdit qte;
QTextStream out(qte);
如果我在写入 QTextStream 后发出信号,我可以做类似的事情 附加到 QString。
问题是我希望界面是 与我流式传输到 stdout 等相同:
out << some data << endl;
关于如何实现此目的有什么想法吗?
提前致谢。
I have often wanted to use QTextEdit as a quick means of displaying what is being written
to a stream. That is, rather than writing to QTextStream out(stdout), I want
to do something like:
QTextEdit qte;
QTextStream out(qte);
I could do something similar if I emit a signal after writing to a QTextStream
attached to a QString.
The problem is that I want the interface to be the
same as it would if I were streaming to stdout
etc.:
out << some data << endl;
Any ideas on how I might accomplish this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个输出到 QTextEdit 的 QIODevice。
You can create a QIODevice that outputs to QTextEdit.
您可以子类化
QTextEdit
并实现<<
运算符以赋予其您想要的行为;像这样的东西:You can subclass the
QTextEdit
and implement the<<
operator to give it the behaviour you want ; something like: