nube:stdio 到 QTextedit

发布于 2024-11-14 09:04:10 字数 1105 浏览 1 评论 0原文

我读过很多与此类似的线程,但我不是一个伟大的程序员,我可以理解这一切。我使用 qtcreator 来让生活变得简单,并希望创建一个可以触发另一个进程、监视其标准输出并在必要时终止它的程序。

我认为我想要做的是在设计器中创建一个 QTextedit 并插入一个信号,每当流更新时更新包含的文本,到目前为止一切顺利,但这就是我变得模糊的地方。我最初的想法是创建一个 QObject 的子类,它作为 QProcess 启动进程,并且每当标准输出更新 QObject 并将新数据附加到 QTextedit 框时。

所以我的程序结构将像这样运行:

按下按钮创建新的 QObject 派生类。

QObject派生类构造函数启动一个QProcess并将readyReadStdout()信号连接到派生qObject类槽。

当派生的 QObject 被触发时,它会调用 readStdout() 并将任何新数据附加到 QTetEdit 框中。

按下按钮时,调用派生的 QObject 析构函数并杀死该进程。

有人做过类似的事情吗?就像我说的,我读过类似的帖子,但有时需要用自己的话问一个问题才能理解它

谢谢大家(也是我的第一篇文章,woo:)


好吧,这是我的更新:

我添加了一个 QProcess 类的实例(命名为 proc)到我的 mainWindow 类,以及 QObject 派生类(名为 procLog)的新实例,我向其中添加了一个槽。我希望此插槽将 readAllStandardOutput() 信号作为触发器来调用 readAllStandardOutput() 并向 procLog 中的新信号发出新行,我在将 QProcess 插槽连接到 QObject 派生类时遇到问题。这就是我正在尝试的:

connect(proc, SIGNAL(readyReadStandardOutput ()), procLog, SLOT(logReady()));

我得到,错误:QObject::connect: Cannot connect (null)::readyReadStandardOutput () to (null)::logReady()

你知道这是为什么吗?还有一种方法可以将代码块添加到注释中的文本中?

谢谢!

I've read lots of similar threads to this one but im not such a great programmer that i can make sense of it all. Im using qtcreator to make life simple and want to maka a program that can trigger another process, monitor its stdout and then kill it if necessary.

What I assume i want to do is create a QTextedit in the designer and plug a signal into it that updates the contained text whenever the stream updates, so far so good, but thats where i get fuzzy. My initial thought was to create a subclass of QObject that starts the process as a QProcess and whenever the stdout updates the QObject and appends new data to the QTextedit box.

So my program structure would run like this:

on button press create new QObject derived class.

The QObject derived class constructor starts a QProcess and connects the readyReadStdout() signal to the derived qObject class slot.

When the derived QObject is triggered it takes readyReadStdout() and appends any new data to the QTetEdit box.

on button press, call the derived QObject destructor and which kills the process.

Has anybody done something similar? Like i say ive read similar posts but sometimes it takes asking a question in your own words to be able to understand it

Thanks everyone (also my forst post, woo:)


Ok so heres my update:

I have added an instance of QProcess class (named proc) to my mainWindow class and also new instance of a QObject derived class (named procLog) to which I added a slot. I want this slot to take the readyReadStandardOutput() signal as a trigger to call readAllStandardOutput() and emit the new line to a new signal in procLog, I'm having trouble connecting the QProcess slot to the QObject derived class. heres what I'm trying:

connect(proc, SIGNAL(readyReadStandardOutput ()), procLog, SLOT(logReady()));

I get, error: QObject::connect: Cannot connect (null)::readyReadStandardOutput () to (null)::logReady()

Do you know why this is. Aslo is there a way to add code blocks to text in the comments?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文