C# Qt 쓰기 호출[email protected]+VS2013(32bit)+win7 32bit
오늘 프로그램을 바꿔서 말을 많이 하지 않고 절차를 쓰고 코드를 쓴다.
1, 인터넷에서 다음 qtwinmigrate:
https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate
qtwinmigrate 폴더에 규칙이 있는 것을 발견하기;
2, Qt에서 컴파일하고 C#에서 호출, OK;
3, 그리고 스스로 프로그램을 써서 dll로 컴파일하고 C#로 호출, OK;
----------------------------------------------------------------
코드는 다음과 같습니다.
Qt dll:
qtui.pro:
TEMPLATE = lib
CONFIG += dll SOURCES = main.cpp \ dialog.cpp TARGET = qtui DLLDESTDIR = $$[QT_INSTALL_PREFIX]/bin include(../../src/qtwinmigrate.pri) FORMS += \ dialog.ui HEADERS += \ dialog.h 프로젝트에 qtwinmigrate 폴더의 src를 추가하는 것을 주의하십시오.
헤더 파일:dialog.h
#ifndef DIALOG_H
#define DIALOG_H #include namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = 0); ~Dialog(); private slots: void on_m_pbCalc_clicked(); private: Ui::Dialog *ui; }; #endif // DIALOG_H cpp:
#include "dialog.h"
#include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; } void Dialog::on_m_pbCalc_clicked() { int add1 = ui->m_lE1->text().toInt(); int add2 = ui->m_lE2->text().toInt(); int sum = add1+add2; QString strSum; strSum.setNum(sum); ui->m_lbSum->setText(strSum); ui->m_lEsum->setText(strSum); } main.cpp
#include
#include #include #include #include "dialog.h" extern "C" __declspec(dllexport) int showDialog() { int argc = 0; //char* argv[] = NULL; QApplication a(argc, NULL); Dialog *dlg = new Dialog(); dlg->show(); return a.exec(); } //int main() //{ // Dialog *dlg = new Dialog(); // dlg->show(); // return 0; //} 인터페이스는 아무것도 없다. 바로 세 개의 텍스트 상자이다. 하나의 덧셈을 실현한다.
C#이쪽은 단순하고 거칠다.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Windows;namespace CSCallQtdll{ public partial class Form1 : Form { [DllImport("qtui.dll")] public static extern int showDialog(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { showDialog(); } }}
인터페이스에 단추가 하나 있습니다.dll를 프로젝트에 추가하면 됩니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Qt로 문자와 이미지의 혼합 텍스트 그리기텍스트를 그리려면 QPainter::drawText 함수를 사용하지만 텍스트와 동시에 이미지 (아이콘 등)를 함께 그리기를 원합니다. QLabel와 QPushButton는 이미지와 텍스트를 표시하는 기능을 가지고 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.