Windows下QtCreator与Qwt集成

版本信息:

(1)msvc2010

(2)Qt5.3.1 + MingW482 + QtCreator3.2.1

(3)Qwt6.1


集成过程:

(1)下载并安装msvc2010

进入http://microsoft-visual-cpp-express.soft32.com/  下载msvc2010在线安装包,安装后会得到msvc2010的编译环境

(2)下载Qwt6.1

        进入http://qwt.sourceforge.net/index.html, 可找到qwt的svn链接, 使用svn工具export到自己定义的目录。

        我的svn链接是:svn://svn.code.sf.net/p/qwt/code/branches/qwt-6.1

(3)将export得到的qwt6.1源码复制两份,一份使用msvc2010编译得到qtcreator插件,一份使用mingw编译得到qwt库

(4)编译qwt6.1的方法是:使用qtcreator打开qwt6.1的pro文件,然后切换到release模式,最后build就可以了(注意:1.我编译时注释掉了qwtbuild.pri中CONFIG += debug_and_release 这一行;2.编译插件与编译库的步骤完全一样;3.不需要其他设置,编译过程也很顺利)。

(5)将build-qwt-Qt5_3_1_MSVC2010-Release/designer/plugins/designer/文件夹中生成的插件qwt_designer_plugin.dll复制到D:/Qt5.3.2/Tools/QtCreator/bin/plugins/designer/这个目录中

(6)重启QtCreator可以看到出现了Qwt的拖拽控件。

(7)编写测试程序,引入qwt需要的头文件和库文件(注意是mingw对应的头文件和库文件)

         QwtTest.pro

#-------------------------------------------------
#
# Project created by QtCreator 2016-10-07T11:31:42
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = QwtTest
TEMPLATE = app


INCLUDEPATH += F:/DayFiles/20161007/qwt6.1-mingw/src

LIBS += -LF:/DayFiles/20161007/build-qwt-Desktop_Qt_5_3_MinGW_32bit-Release/lib -lqwt

SOURCES += main.cpp\
        mainwidget.cpp

HEADERS  += mainwidget.h

FORMS    += mainwidget.ui

        mainwidget.h

#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>

namespace Ui {
class MainWidget;
}

class MainWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MainWidget(QWidget *parent = 0);
    ~MainWidget();

private:
    Ui::MainWidget *ui;
};

#endif // MAINWIDGET_H

 

       mainwidget.cpp

#include "mainwidget.h"
#include "ui_mainwidget.h"

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);
}

MainWidget::~MainWidget()
{
    delete ui;
}
      mainwidget.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWidget</class>
 <widget class="QWidget" name="MainWidget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>598</width>
    <height>350</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWidget</string>
  </property>
  <widget class="QwtAnalogClock" name="AnalogClock">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>20</y>
     <width>191</width>
     <height>111</height>
    </rect>
   </property>
   <property name="lineWidth">
    <number>4</number>
   </property>
  </widget>
  <widget class="QwtKnob" name="Knob">
   <property name="geometry">
    <rect>
     <x>200</x>
     <y>0</y>
     <width>150</width>
     <height>150</height>
    </rect>
   </property>
  </widget>
  <widget class="QwtPlot" name="qwtPlot">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>150</y>
     <width>321</width>
     <height>171</height>
    </rect>
   </property>
  </widget>
  <widget class="QwtThermo" name="Thermo">
   <property name="geometry">
    <rect>
     <x>370</x>
     <y>10</y>
     <width>61</width>
     <height>301</height>
    </rect>
   </property>
  </widget>
  <widget class="QwtWheel" name="Wheel">
   <property name="geometry">
    <rect>
     <x>480</x>
     <y>30</y>
     <width>91</width>
     <height>31</height>
    </rect>
   </property>
  </widget>
  <widget class="QwtSlider" name="Slider">
   <property name="geometry">
    <rect>
     <x>470</x>
     <y>80</y>
     <width>111</width>
     <height>71</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <customwidgets>
  <customwidget>
   <class>QwtPlot</class>
   <extends>QFrame</extends>
   <header>qwt_plot.h</header>
  </customwidget>
  <customwidget>
   <class>QwtAnalogClock</class>
   <extends>QwtDial</extends>
   <header>qwt_analog_clock.h</header>
  </customwidget>
  <customwidget>
   <class>QwtDial</class>
   <extends>QWidget</extends>
   <header>qwt_dial.h</header>
  </customwidget>
  <customwidget>
   <class>QwtKnob</class>
   <extends>QWidget</extends>
   <header>qwt_knob.h</header>
  </customwidget>
  <customwidget>
   <class>QwtSlider</class>
   <extends>QWidget</extends>
   <header>qwt_slider.h</header>
  </customwidget>
  <customwidget>
   <class>QwtThermo</class>
   <extends>QWidget</extends>
   <header>qwt_thermo.h</header>
  </customwidget>
  <customwidget>
   <class>QwtWheel</class>
   <extends>QWidget</extends>
   <header>qwt_wheel.h</header>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

     编译后运行效果:



知识点:

(1)注意QtCreator使用了msvc编译,若要使用qwt在qtcreator中的控件拖拽功能,则必须使用msvc编译qwt的qtcreator插件。而编译自己的qwt的应用程序时还是使用mingw来编译,则还需要使用mingw编译出qwt的库。

(2)我的qtcreator是qtcreator3.2.1, 其基于Qt5.3.2, 不能使用Qt5.3.2以上的qt版本来编译qwt的qtcreator插件,否则会出现插件不能识别的情况。

(3)不能使用MSVC2013 + Qt5.3.1_MSVC2010 这样的组合来编译qwt,而一定要保证Qt对应的MSVC编译器版本与实际使用的版本一致,否则可能出现如下问题:

          ****   if multiple CL.EXE write to the same .PDB file, please use /FS ***


仅供学习参考!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值