導航:首頁 > 編程語言 > 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調用外部程序相關的資料

熱點內容
電極自動編程哪個軟體好用 瀏覽:550
cad看圖大師下載的文件在哪 瀏覽:227
硬碟損壞內部數據怎麼修 瀏覽:880
微信你真列害圖片大全 瀏覽:49
jsin類型可以傳數值嗎 瀏覽:532
win10文件從左邊滑出 瀏覽:53
win10關機後桌面文件丟失 瀏覽:266
watch卸載自帶應用程序 瀏覽:292
有什麼plc自學網站 瀏覽:219
176純金幣假人版本 瀏覽:334
紅米note4微信計步代碼 瀏覽:259
站長之家有app嗎 瀏覽:912
office應用視頻教程 瀏覽:690
html資料庫有哪些 瀏覽:489
鋼筆工具線不會變細 瀏覽:762
access2010資料庫上機 瀏覽:686
flstudio錄音教程 瀏覽:457
圖形編程軟體哪個好用 瀏覽:393
要怎麼重新下載而且不保存數據 瀏覽:188
手機軟體下載後文件在哪 瀏覽:515

友情鏈接