【发布时间】:2020-12-10 21:43:31
【问题描述】:
我有一个正在开发的 QT 应用程序,它本质上是一个 GUI,可以从几个不同的内部开发子模块启动程序,以及在这个应用程序本身内部开发的一些例程。但是,我遇到了障碍。其中一个子模块被开发为能够作为独立库 (.a) 运行。
这个库是使用在命令行上编译的主 cpp 运行的。
main.cpp 的示例代码
// these functions are called inside the library, but implemented in main.cpp for flexibility
void printMsg(String& msg){
// prints/cout msg
}
int printPrompt(String& str1, String& str2){
// it prints str1 and str2 as prompt
// gets the user input from console that is returned as int return value
// library uses this return value to do various task
}
main(){
runLibApp() // this function is in the library that starts the execution
}
我想要弹出窗口来处理消息、提示和用户输入。我确实在主窗口类中定义了一个弹出函数,该函数在其他地方使用,但它只在主窗口类和几个 QT 子类中调用。
由于这个库不是 QT 子类,我不能在其中使用我的 QT 弹出函数。在不破坏库本身的情况下,我无法将函数重新定义为 QT 子类的一部分。
有没有什么方法可以将我的 QT 弹出函数连接到这个库,而不必彻底重做这个库?
【问题讨论】:
-
也许你可以将它作为一个单独的应用程序运行,并通过重定向标准输入和标准输出来做一些时髦的事情?
-
在 QProcess 中,您可以读取输出并将输入发送到外部命令行程序。