QT5入門之19 QT呼叫外部程式

2021-07-06 05:10:03 字數 1022 閱讀 8304

很簡單,用qprocess即可。

#include 

void mainwindow::on_pushbutton_5_clicked()

process.execute("calc");//開啟計算器

process.execute("regedit");//開啟登錄檔

process.execute("notepad");//開啟記事本

process.execute("notepad d:\1.txt");//用記事本開啟d盤下1.txt檔案

但是這種方式會導致主線程阻塞。

另外一種方式是另外開個執行緒啟動外部程式。

1. 新建c++ class。

mythread.h

#include 

#ifndef mythread_h

#define mythread_h

class mythread : public qthread

;#endif // mythread_h

mythread.cpp

#include "mythread

.h"#include

mythread

::mythread()

mythread::~mythread()

void

mythread

::run()

2.在主窗體中定義成員變數並呼叫start啟動。

#include

"mythread.h"

class mainwindow : public qmainwindow

;void mainwindow::on_pushbutton_5_clicked()

也許會出現無法解析的外部符號 「public: __thiscall mythread:錯誤,手動刪除debug目錄,重新編譯即可。

QT5入門之24 QT 容器

和標準stl一樣,qt也有很多容器。qt 提供了順序儲存容器 qlist,qlinkedlist,qvector,qstack 和 qqueue。對於絕大多數應用程式,qlist 是最好的選擇。雖然它是基於陣列實現的列表,但它提供了快速的向前新增和向後追加的操作。如果你需要鍊錶,可以使用 qlink...

QT5入門之23 QT串列埠程式設計

qt5有專門的串列埠類 qserialport 提供訪問串列埠的功能 qserialportinfo 提供系統中存在的串列埠的資訊 具體使用方法 1.在pro檔案中加入 qt serialport 2.mainwindow.h中新增標頭檔案及成員 include include public qse...

Qt之呼叫外部DLL

宣告 事先我已經自己動手寫了乙個簡單的dll檔案 mydll.dll c版介面的。首先,從dll中匯出了導入庫 lib 檔案,dll中有兩個函式,原型如下 void helloworld 函式內部呼叫win32 api,功能是彈出乙個helloworld提示框 int add int a,int b...