初學Qt之 在Qt中呼叫外部C語言模組

2021-06-26 09:11:36 字數 1680 閱讀 6843

呼叫外部已編譯好的c語言模組,傳遞引數並將結果返回列印出來。

c語言模組**:

[cpp]view plain

copy

print?

/**********test.c**********/

/**********用gcc編譯後生產那個的可執行檔案test放在..../invokec/c/目錄下**********/

#include 

int main(int argc,char *argv)    

/**********test.c**********/

/**********用gcc編譯後生產那個的可執行檔案test放在..../invokec/c/目錄下**********/

#include int main(int argc,char *argv)

qt**:

[cpp]view plain

copy

print?

/********mytest.h***********/

#ifndef mytest_h_

#define mytest_h_

#include 

#include 

class mytest : public qwidget  

;  #endif

/********mytest.h***********/

#ifndef mytest_h_

#define mytest_h_

#include #include class mytest : public qwidget

;#endif

[cpp]view plain

copy

print?

/********mytest.cpp**********/

#include "mytest.h"

#include 

#include 

#include 

#include 

mytest::mytest()  

:qwidget()  

mytest::~mytest()  

void mytest::invokec()    

/********mytest.cpp**********/

#include "mytest.h"

#include #include #include #include mytest::mytest()

:qwidget()

mytest::~mytest()

void mytest::invokec()  

/***********main.cpp************/

/*******編譯後放在...../invokec/qt/目錄下************/

int main(int argc,char *argv)

執行結果:

(--------完--------)

qt呼叫外部exe

startdetached啟動的libfx.exe跟你的程序沒關係,你的程式關了它還可以繼續執行 qstring strfile tr e f libfx.exe qprocess pprocess new qprocess this pprocess startdetached strfile s...

QT呼叫外部程式

qt呼叫外部程式 system calc.exe qprocess execute calc.exe qprocess startdetached calc.exe qprocess pro new qprocess pro start calc.exe 注釋 1 前兩種方法會阻塞程序,直到計算器程...

Qt 呼叫外部C動態庫

先寫乙個測試程式 test.h include test test.c include test printf hello,1234 做成動態庫,gcc o fpic shared o libtest.so test.h test.c 將libtest.so和test.h拷貝到qt的工程目錄,在pr...