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

熱點內容
aecc視頻教程 瀏覽:983
linux怎麼查看資料庫用戶名 瀏覽:182
cefs文件系統 瀏覽:404
學平面設計個編程哪個好 瀏覽:701
如何把編程文件轉為hex 瀏覽:80
清除蘋果地圖來自地址 瀏覽:233
已經打開的文件如何清理 瀏覽:685
視頻網站有什麼用 瀏覽:70
多個表格文件怎樣壓縮文件 瀏覽:729
cad文件大很卡如何解決 瀏覽:633
將java程序打包成apk 瀏覽:277
2021唱吧文件找不到了 瀏覽:463
華為p9手機文件管理 瀏覽:284
固定在工具欄的文件夾怎麼查找路徑 瀏覽:667
半條命2有幾個版本 瀏覽:333
電腦管家微信備份文件夾 瀏覽:826
ubuntu文件夾解鎖 瀏覽:34
網站多少錢一單 瀏覽:382
系統鏡像恢復找不到文件 瀏覽:255
進什麼網站 瀏覽:588

友情鏈接