导航:首页 > 编程语言 > 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调用外部程序相关的资料

热点内容
海克斯康三次元如何编程循环测量 浏览:518
app无法下载是为什么苹果手机 浏览:518
右击此电脑管理找不到此文件 浏览:264
图像文件格式百科 浏览:523
没有网络怎么定位 浏览:972
剪切到优盘文件找不到了 浏览:764
电脑管家的文件名 浏览:910
如何将扫描文件转换为电子版 浏览:4
u盘的h246文件怎么播放 浏览:203
如何用阿里云服务器学习数据库 浏览:84
华为文件管理找不到下载文件 浏览:409
word模板dot的使用 浏览:466
春节车找人app哪个好 浏览:618
文件管理电脑找不到了怎么办 浏览:516
如何改变app图标图片 浏览:767
什么是大数据结构的最低层 浏览:575
pdf文件给对方后期改密码收回 浏览:295
word2010怎么画箭头 浏览:184
win10的自动备份文件在哪个目录 浏览:843
文件夹打包成jar 浏览:456

友情链接