QtCreator代码生成器之opencv版本

一、效果图:

1.新建项目

2.配置工程

3. 自动生成的cpp文件

.

4.自动生成的pro文件



二、基本方法

Qt提供了用户自定义Wizards的方法,在Qt的安装路径下:G:\softwareWin8\Qt_free\Tools\QtCreator\share\qtcreator\templates\wizards,是软件自带的向导,参考它的写法,就可以写自己的Wizards.

三、具体步骤

1、在G:\softwareWin8\Qt_free\Tools\QtCreator\share\qtcreator\templates\wizards文件夹下新建文件夹,命名“opencv_wizard”,在新文件夹下,新建一个xml文件,命名为“wizard.xml”(一定要这个名字)

2、wizard.xml的代码如下


<?xml version="1.0" encoding="UTF-8"?>
<!--
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

Custom project wizard configuration example file. Note that by convention,
the project file goes last.
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
        class="qmakeproject" firstpage="10"
        id="A.newplugin" category="B.CustomProjects">
    <strong style="color: rgb(255, 0, 0);"><icon></strong>opencv-logo.png<strong style="color: rgb(255, 0, 0);"></icon></strong>
    <description>Creates an simple OpenCV demo.</description>
    <displayname>OpenCV App</displayname>;
    <displaycategory>Custom Projects</displaycategory>
    
    <span style="color:#ff0000;"><strong><files></strong></span>
        <file source="myopencv.cpp" target="%PluginName:l%.%CppSourceSuffix%" openeditor="true"/>
        <file source="myopencv.pro" target="%PluginName:l%.pro" openproject="true"/>  
    <span style="color:#ff0000;"><strong></files></strong></span>
	
    <!-- Create a 2nd wizard page with parameters -->
    <fieldpagetitle>OpenCV Configuration</fieldpagetitle>
    <span style="color:#ff0000;"><strong><fields></strong></span>
	  <!-- Plugin name field -->
        <field mandatory="true" name="PluginName">
            <fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$"
                          defaulttext="MyOpenCV" />
            <fielddescription>Applicantion name:</fielddescription>
        </field>
		<field mandatory="true" name="opencv_path">
			<fieldcontrol class="Utils::PathChooser" 
						  defaulttext="G:\softwareWin8\opencv\build"/>
			<fielddescription>OpenCV path:</fielddescription>
		</field>
		<field name="opencv_version">
			<fielddescription>OpenCV version:</fielddescription>
			<fieldcontrol class="QComboBox" defaultindex="0">
				<comboentries>
					<comboentry value="249">
						<comboentrytext>2.4.9</comboentrytext>
					</comboentry>
					<comboentry value="300">
						<comboentrytext>3.0.0</comboentrytext>
					</comboentry>
				</comboentries>
			</fieldcontrol>
		</field>
		<field name="compile_type">
			<fielddescription>Compile type:</fielddescription>
			<fieldcontrol class="QComboBox" defaultindex="1">
				<comboentries>
					<comboentry value="x86">
						<comboentrytext>32 bits</comboentrytext>
					</comboentry>
					<comboentry value="x64">
						<comboentrytext>64 bits</comboentrytext>
					</comboentry>
				</comboentries>
			</fieldcontrol>
		</field>
		<field name="core">
			<fieldcontrol class="QCheckBox" defaultvalue="true" truevalue="" falsevalue="# "/>
            <fielddescription>core</fielddescription>
		</field>
		<field name="highgui">
			<fieldcontrol class="QCheckBox" defaultvalue="true" truevalue="" falsevalue="# "/>
            <fielddescription>highgui</fielddescription>
		</field>
		<field name="imgproc">
			<fieldcontrol class="QCheckBox" defaultvalue="true" truevalue="" falsevalue="# "/>
            <fielddescription>imgproc</fielddescription>
		</field>
		<field name="calib3d">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>calib3d</fielddescription>
		</field>		
		<field name="gpu">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>gpu</fielddescription>
		</field>
		<field name="legacy">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>legacy</fielddescription>
		</field>		
		<field name="ml">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>ml</fielddescription>
		</field>
		<field name="features2d">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>features2d</fielddescription>
		</field>		
		<field name="nonfree">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>nonfree</fielddescription>
		</field>
		<field name="objdetect">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>objdetect</fielddescription>
		</field>
		<field name="ocl">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>ocl</fielddescription>
		</field>
		<field name="photo">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>photo</fielddescription>
		</field>		
		<field name="stitching">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>stitching</fielddescription>
		</field>
		<field name="superres">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>superres</fielddescription>
		</field>		
		<field name="video">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>video</fielddescription>
		</field>
		<field name="videostab">
			<fieldcontrol class="QCheckBox" truevalue="" falsevalue="# "/>
            <fielddescription>videostab</fielddescription>
		</field>
	
	</fields>
	
</wizard>

代码比较简单,非常好懂。

<icon>的内容是图标的名字,这个图标需要保存在wizard.xml同路径下。

<files>是需要复制的代码文件,也需要保存在wizard.xml同路径下。

<fields>是自己添加的内容,它会出现在项目配置页中,如上面第2张图。

添加的代码文件可以通过wizard.xml元素的元素名访问它的值,这样通过钩钩叉叉就配置opencv的路径了,不用自己写pro文件了。


代码下载


Qt官方有更详细的说明




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值