导航:首页 > 编程语言 > qt调用外部程序

qt调用外部程序

发布时间:2023-08-25 14:41:59

『壹』 QT调用外部程序打开聊天窗口

// 设置一个高频定时器,移动当前窗口位置,然后又移动回来,来回手早交替就可以败樱了!~QTimer *timer = new QTimer(this);timer->start(10);connect(timer, SIGNAL(timeout()), this, SLOT(sltTimeout()));void MainWindow::sltTimeout() { static int nX = this->rect().x(); static int nY = this->rect().y(); if (nX == this->rect().x()) this->毕枯雀move(nX-10, nY -10); else this->move(nX, nY);}

『贰』 Qt QProcess

本文介绍,在Linux环境下,使用Qt中的 QProcess 类执行shell命令并获取输出。
文件: #include <QProcess>

一、函数接口
QProcess 类提供了三个函数

二、执行命令
这里主要介绍 execute() 和 start() :

execute() 会将命令输出直接打印到控制台,调用程序无法捕获。

调用程序可通过 readAllStandardOutput() 捕获shell命令的输出

三、管 道
对于shell命令中的 | ,直接传入参数是不行的。

以上的方式是无法执行的。
可以将整个命令作为 sh 的参数传入 或 使用 QProcess::setStandardOutputProcess(QProcess *destination) 即将一个进程的标准输出流传入目标进程的标准输入流

对于需要sudo权限的命令,需要使用sudo权限打开qtcreator,或者直接在命令前加上sudo(不建议)。

当然, QProcess 不仅仅可以执雀厅行shell命令旅早,也可以用于执行调拆岁雀用外部程序。

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

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");

『肆』 Qt调用外部程序的问题

先看看返回值是多少?灶丛灶如隐扮果调用成功,使用
startDetached(const QString& program, const QStringList & arguments, const QString & workingDirectory, qint64 * pid = 0 ) 函数,看看pid是郑敬多少。

『伍』 Qt打开外部程序(界面与程序连接)

#include<Qprocess>

void MainWindow2::program() //打开外部程序

{

    this->hide();  /枯凯/隐藏型薯当前界面

    QProcess::execute("……\\xx.exe");   //外部没租唤程序所在路径

}

『陆』 qt调用外部exe程序并且将exe程序一起打包

你试试作为一个资源来运行看行不行,或者将exe作为一个资源,然后运行回时以二进制的形式读取,再答将读取到的二进制信息写入到临时文件中,运行临时文件。或者直接将资源中得exe保存到系统临时文件夹中进行运行。
只是个思路,没试过,你试试

『柒』 QT 启动与关闭外部程序

启动

QString filepath = QDir::currentPath();

    QString fullpath = filepath+"\\pp\\dist\\start";

    QString title = fullpath+"\\main.exe";

    title = title.replace("/","\\");

    fullpath = fullpath.replace("/","\\");

   袜答 QProcess p(this);

    p.setWorkingDirectory(fullpath);

    p.start("cmd", QStringList()<<"/c"<<"start main.exe");

    p.waitForStarted();

    p.waitForFinished();

关闭

    QProcess p(this);

    p.setWorkingDirectory(fullpath);

   庆洞 p.start("告差慧cmd", QStringList()<<"/c"<<"taskkill /f /t /im main.exe");

    p.waitForStarted();

    p.waitForFinished();

阅读全文

与qt调用外部程序相关的资料

热点内容
如何删除己下载未安装的文件 浏览:806
招商银行app怎么登陆二类卡 浏览:508
谷歌浏览器的debug调试工具 浏览:163
哪个数控编程是免费的 浏览:368
苹果7plus玫瑰金报价 浏览:800
杭州自行车系统微信号 浏览:352
网络语偷猪是什么意思 浏览:309
三星i9300线刷教程图解 浏览:248
编程竞赛特训哪里好 浏览:28
提取驱动文件 浏览:102
如何压缩wps文件 浏览:314
ps转ico文件 浏览:303
无编程计算器是指哪些 浏览:852
jquery服务器返回json数据格式 浏览:375
pl0编译程序文本c版本 浏览:687
cocos2djs开发 浏览:124
怎么取消苹果电脑密码怎么设置 浏览:950
word2013序列号 浏览:462
fu是什么海淘网站 浏览:620
u盘和充电器数据线哪个好 浏览:969

友情链接