qt中如何运行外部程序,QProcess类

qt中如何运行外部程序,QProcess类,第1张

QT中使用QProcess启用外部程序启用外部程序,并可传参,默认第一个参数是exe路径!启动外部程序的方法有以下两种:1、start()void QProcess::start ( const QString &program, const QStringList &arguments, OpenMode mode = ReadWrite )Starts the program program in a new process, passing the command line arguments in arguments. The OpenMode is set to mode. QProcess will immediately enter the Starting state. If the process starts successfully,QProcess will emit started()otherwise, error() will be emitted.Note that arguments that contain spaces are not passed to the process as separate arguments.Windows: Arguments that contain spaces are wrapped in quotes.Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.See also pid(), started(), and waitForStarted().2、使用QProcess::execute(), 不过使用此方法时程序会谈纤则最阻塞直到此方法执行的程序结束后返回,这时竖巧候可使用QProcess和QThread这两个类结合使用的方法来处理,以防止在主 线程中调用而导致阻塞的情况先从QThread继承一个类,重新实现run()函数:答:1、使用QProcess::startDetached()方法,启动外部程序后立即返回;2、使用QProcess::execute(),不过使用此方法时程序会最阻塞直到此方法执行的程序结束后返回,这时候可使用QProcess和QThread这两个类结合使用的方法来处理,以防止在主含棚线程中调用而导致阻塞的情况先从QThread继承一个类,重新实现run()函数:Quote:class MyThread : public QThread{public:void run()}void MyThread::run(){QProcess::execute("notepad.exe")

1 需要保证linux下要安装了qt环境罩链

2 进入你闭逗的程序目录,运行 /usr/local/qt_install/bin/qmake xxxx.pro。 其中/usr/local/qt_install是qt安装目录. xxxx.pro是你应程程序中的pro文件

3 执行物态孙make

4 运行生成的bin文件


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12505655.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存