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

熱點內容
網路小說用什麼寫 瀏覽:956
擴展名為rm的文件如何打開 瀏覽:707
導入android項目沒有rjava 瀏覽:899
帶英文和數字的文件名 瀏覽:843
黃山數控編程培訓在哪裡 瀏覽:111
win10俠盜5無限讀取 瀏覽:557
js工廠模式 瀏覽:927
iphone6s清理緩存 瀏覽:465
ug編程怎麼選不上字體 瀏覽:435
pc文件加密哪個好 瀏覽:393
蘋果軟體更新4位密碼 瀏覽:96
手機如何將文件弄成文件夾 瀏覽:275
swordigo第四關 瀏覽:996
t420win10網卡驅動 瀏覽:805
ps怎麼打開dxf文件怎麼打開 瀏覽:698
ps格式文件打開軟體 瀏覽:371
下載網路資源遇到哪些問題 瀏覽:887
抖音交友app廣告怎麼投 瀏覽:870
esxiha配置文件 瀏覽:573
pubg交易平台有哪些APP 瀏覽:144

友情鏈接