lihao2014 发表于 2015-2-4 10:43:28

CAD控件:QT开发使用控件入门



1. 环境搭建:
1.1、 安装Qt
官网地址:(梦想,CAD,控件)进入官网,点击 到下载页面
如下:http://img.blog.csdn.net/20150129155718784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

再点击,不使用它的在线安装,太慢,再点击[View All Downloads可以看到离下载包,如下:我这里选择VC2010开发包
http://img.blog.csdn.net/20150129155817471?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

在下面的[Other downloads,下载vs开发插件,如下
:http://img.blog.csdn.net/20150129155842385?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

下载后文件如下:
http://img.blog.csdn.net/20150129155920043?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

点击“梦,。想,CAD,控件,   ”安装如下:
http://img.blog.csdn.net/20150129160021420?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
默认我安装在“C:\Qt\Qt5.4.0”目录

选择组件页面,把所有的安装都选上,再点击[下一步],直到安装完成:
http://img.blog.csdn.net/20150129160134725?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

点击“                         ”,在Visual Studio中安装QT开发插件,按照安装提示安装,安装完后,VS新建项目就多个QT选项,如下:
http://img.blog.csdn.net/20150129160233983?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

1.2、 安装Microsoft Windows SDK的调试包
默认下情况下,QtCreator在Windows环境下,是不能单步调试程序,会提示“调试器未设置”,需要安装Microsoft Windows SDK的调试包。
Microsoft Windows               搜索(梦。。想,。CAD 控件)如下:
http://img.blog.csdn.net/20150129160305011?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

下击下载iso包
http://img.blog.csdn.net/20150129160438330?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
下载GRMSDK_EN_DVD.iso
打开ISO安装包,找了目录 Setup\WinSDKDebuggingTools中的dbg_x86.msi文件安装。一般选择默认安装。如果是64位系统,同时安装一下Setup\WinSDKDebuggingTools_amd64\dbg_amd64.mis。
打开 ->[工具]->[选项] ->[构建和运行]::构建套件(Kit)-> [手动设置]:桌面 -> [调试器]:自动检测,这样就可以检测到安装的调试器了。
http://img.blog.csdn.net/20150129160433205?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
然后,重启Qt Creator,就可以调试工程了;
2. QT中使用MxDraw控件
详细介绍如何把控件放到QT中,并运行
1.3、 引入控件
运行Qt Creator,点击[文件]=>[新建文件或项目..],出来新建项目窗口,如下:
http://img.blog.csdn.net/20150129160550106?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
选择”Qt Widgets Application” 新建一个桌面项目

http://img.blog.csdn.net/20150129160557383?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
新建项目完成,点击”mainwindow.ui”,进入界面编辑,如下图:
http://img.blog.csdn.net/20150129160702553?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
在界面上,插入COM组件,如下图:

http://img.blog.csdn.net/20150129160727591?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
运行控件安装下的RegMxDrawX.bat注册控件,只有注册了控件,在下面的界面才能看到MxDraw52,如下图:
http://img.blog.csdn.net/20150129162243662?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

双击,拖到界面的COM组件,选择MxDrawX52
http://img.blog.csdn.net/20150129162337701?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
现在需要编译运行,出现如下连接错误提示,是因为工程中,没有加入Qt Axcontainer,错误提示如下:
http://img.blog.csdn.net/20150129162403862?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

修改工程属性文件:TestQtMxDraw.pro,加入QT += axcontainer,如下
http://img.blog.csdn.net/20150129162800078?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

保存TestQtMxDraw.pro文件,然后运行[构建]=>[执行qmake]编译TestQtMxDraw.pro文件
如下图:
http://img.blog.csdn.net/20150129162854312?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

然后构建所有项目 ,前面的连接错误就消除了。

点击运行后如下图:
http://img.blog.csdn.net/20150129162910980?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
3. 打开DWG文件
演示如何在QT调用控件打开函数,打开DWG文件
1.4、 增加打开文件按钮
在界面上放一个按钮,并生成按钮事件,
http://img.blog.csdn.net/20150129162947383?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

点按钮上点击右键,选择[转到槽,增加按钮点击事件
http://img.blog.csdn.net/20150129162933740?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
点击[转到槽:
http://img.blog.csdn.net/20150129163011797?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
增加如下代码:
void MainWindow::on_pushButton_clicked(){
    // 执行控件自定义命令函数,命令的id为2,这个id用户可以自己取任意数,可以理解为是给执行的命令一个编号.    ui->axWidget->dynamicCall("DoCommand(const qint32&)",2);}给控件增加,命令显示事件,如下图:
http://img.blog.csdn.net/20150129162952289?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

在函数中,增加如下代码,打开H盘的1.dwg文件:
void MainWindow::on_axWidget_ImplementCommandEvent(int iCommandId)
{
    if(iCommandId == 2)
    {
      // 调用控件打开函数,打开H:盘的1.dwg文件。
      ui->axWidget->dynamicCall("OpenDwgFile(const QString&)","H:\\1.dwg");
}
}

1.5、 在VS中使用QT
运行VS,点=>[Open Qt Project File(.pro)...文件,把刚才我们用Qt Creator引入的到VS中。
如下:http://img.blog.csdn.net/20150129163000884?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Centerhttp://img.blog.csdn.net/20150129163009792?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center




导入后,就可以直接编译运行,是不是很简单。
到这里,恭喜你,使用QT开发我们控件已经入门了…
http://img.blog.csdn.net/20150129163022990?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzcyNTAwMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
页: [1]
查看完整版本: CAD控件:QT开发使用控件入门