日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言程序可以放到qt,初学Qt之--在Qt中调用外部C语言模块

發布時間:2024/3/24 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言程序可以放到qt,初学Qt之--在Qt中调用外部C语言模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

調用外部已編譯好的C語言模塊,傳遞參數并將結果返回打印出來。

C語言模塊代碼:

/**********Test.c**********/

/**********用gcc編譯后生產那個的可執行文件test放在..../invokec/C/目錄下**********/

#include

int main(int argc,char *argv[])

{

printf("Hello,I am a C program!\n");

printf("now,I am invoked by a program called Qt!\nfollowing are the parameters that Qt sends to me:\n");

printf("%s\n",argv[0]);

printf("%s\n",argv[1]);

printf("%s\n",argv[2]);

return 0;

}

Qt代碼:

/********MyTest.h***********/

#ifndef MYTEST_H_

#define MYTEST_H_

#include

#include

class MyTest : public QWidget

{

Q_OBJECT

public:

MyTest();

~MyTest();

public slots:

void invokeC();

private:

QPushButton *pb;

};

#endif

/********MyTest.cpp**********/

#include "MyTest.h"

#include

#include

#include

#include

MyTest::MyTest()

:QWidget()

{

this->setGeometry(0,0,200,50);

pb=new QPushButton("點擊調用C程序",this);

pb->setGeometry(0,0,200,50);

connect(pb,SIGNAL(clicked()),this,SLOT(invokeC()));

}

MyTest::~MyTest()

{

}

void MyTest::invokeC()

{

QProcess *process=new QProcess();

QStringList str;

str.clear();

str << "a" << "b" ;

process->start("../C/test",str);

process->waitForStarted();

process->waitForFinished();

QByteArray qb=process->readAll();

QString str22(qb);

QTextStream cout(stdout);

cout<

}

/***********Main.cpp************/

/*******編譯后放在...../invokeC/Qt/目錄下************/

#include

#include

#include "MyTest.h"

int main(int argc,char *argv[])

{

QApplication a(argc,argv);

QTextCodec *codec = QTextCodec::codecForLocale();

QTextCodec::setCodecForCStrings(codec);

a.setFont(QApplication::font());

MyTest *mt=new MyTest;

mt->show();

return a.exec();

}

運行結果:

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

總結

以上是生活随笔為你收集整理的C语言程序可以放到qt,初学Qt之--在Qt中调用外部C语言模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。