❶ 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 之啟動putty,winscp
簡述
QProcess可以用來啟動外部程序,並與它們交互。
要啟動一個進程,通過調用start()來進行,參數包含程序的名稱和命源激令行參數,參數作為一個QStringList的單個字元串。
另外,也可以使用setProgram()和setArguments()來運行,然後調用start()或open()。
介面———————————謹冊—————
start() 啟動外部程序
readAllStandardError() 從標准錯誤祥裂宏中獲取所有數據
readAllStandardOutput() 從標准輸出中獲取所有數據
write() 繼承於QIODevice
close() 繼承於QIODevice
除此之外,QProcess還包含靜態成員函數:
execute() 啟動一個進程,然後等待該進程結束。
startDetached() 啟動一個進程,然後使其和當前進程脫離進程的父子關系。
❸ qt調用外部exe程序並且將exe程序一起打包
你試試作為一個資源來運行看行不行,或者將exe作為一個資源,然後運行回時以二進制的形式讀取,再答將讀取到的二進制信息寫入到臨時文件中,運行臨時文件。或者直接將資源中得exe保存到系統臨時文件夾中進行運行。
只是個思路,沒試過,你試試
❹ 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 啟動與關閉外部程序
啟動
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調用外部程序的問題
先看看返回值是多少?灶叢灶如隱扮果調用成功,使用
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調用外部程序
1、通過調用Linux C 函數
system("calc.exe");
2、通過碧梁QProcess 阻塞調用
QProcess::execute("calc.exe");/QProcess::startDetached("calc.exe");
3、通過QProcess,非阻塞調用
QProcess *pro = new QProcess;
pro->start("calc.exe");
注釋:
1、前兩種方法會阻塞進程,直到計算器程序結束,而第三種方法則不會阻塞進程,可以多任務運行。
2、QT在運行的時候,要啟動qws服務尺虛,如果用前兩種方法,運行的時候,要新開啟一個qws,否則不能運行;而第三種方法,則不需要在開啟qws,他和主進程公用一個qws。
3、第三種雖然不會阻塞,但是有可能在終端上看不到列印出來的信息。所以要在終端顯示信息,可以考陵慧燃慮阻塞模式。
❾ 將外部程序嵌入qt
網上搜了下實現方案,原理很簡單,就是通過獲取外部窗口的id,轉換為QWindow嵌入當前qt窗口氏宴唯。於是問題就變成了如何查看外部程序的窗口屬性,推薦使用spy++,小巧實用,放鏈接:
鏈接:https://pan..com/s/15cZuL1OPITdM1OwnTkBSww
以記事本程序為例,可以祥薯看到窗口標題為"無標題-殲培記事本",類型為Notepad。
❿ 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命令旅早,也可以用於執行調拆歲雀用外部程序。