问题描述
我正在尝试使用 Qt 为要在 Windows 命令行中运行的现有应用程序设置 GUI.这不仅仅是运行应用程序system()
命令,但我需要通过命令行与现有应用程序交互.
i'm trying to set up a GUI with Qt for an existing application which is meant to be run in the windows commandline. It's not just running the app with the
system()
command, but i need to interact with the existing application via command line.
当我启动现有的可执行文件时,system()
命令会阻止 GUI.如何在后台运行此可执行文件并通过我自己的 GUI 元素(例如按钮)触发一些输入?
The system()
command blocks the GUI when i start the existing executable. How can i run this executable in the background and trigger some inputs via my own GUI-Elements such as a button?
我想为我的一些同事简化这个命令行工具的使用.
I want to simplify the usage of this command line tool for some of my colleagues.
它主要用于windows.
It would be mainly used on windows.
感谢您的帮助.
推荐答案
我找到了满足我需求的解决方案并且可以做我想做的事情.. 其实我有点失望.我认为它会更复杂.
I found a solution for my needs and can do what i want to do.. Actually i'm a bit disappointed. I thought it would be something more complex.
首先我得说这是一个 QtQuick 应用程序 .. 也许我应该早点说.
First i have to say it's an QtQuick Application .. Maybe i should have said that earlier.
我只是将流程功能外包给另一个班级.此类通过 qmlRegisterType<>()
函数传递给 QML.我将来自进程的一些信号 ( QProcess
) 连接到我自己类中的插槽,并编写了自己的函数来处理从控制台应用程序读取数据和向控制台应用程序写入数据.通过 QML-onClicked
事件,我可以将参数和字符串传递给控制台应用程序.通过一些应用程序逻辑,我可以处理输入/输出请求和时间.
I simply outsourced the process functions to another class. This class is passed to QML via the qmlRegisterType<>()
function. I connected some signals from the process ( QProcess
) to slots in my own class and wrote my own functions to handle reading/writing data from and to the console application. With the QML-onClicked
events i can pass my parameters and strings to the console app. And with some application logic i can handle the in/out requests and timings.
WrapperClass.h
WrapperClass.cpp
Main.cpp
通过将 Cpp-Class 注册到 QML,我能够通过来自 QML-MouseArea
或 Button
的 Click-Events 触发读/写功能.
With registering the Cpp-Class to QML i'm able to trigger the read/write functions via Click-Events from QML-MouseArea
or Button
.
这篇关于为 Windows 上现有的基于控制台的应用程序创建 QT 应用程序作为 GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!