1、 建立初始目录文件夹
2、将必要的外部库放到初始文件夹中
例如这里的sdk以及shadow
3、建立cpp文件夹用于存放项目代码
4、建立主工程的必要文件
(1)make.bat文件,将指令qmake -tp vc -r写到bat文件中,用于生成vs项目的sln文件
(2).pro文件:
TEMPLATE = subdirs
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
SUBDIRS += src/practice01
SUBDIRS += src/practice02
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
SUBDIRS += src/practice01
SUBDIRS += src/practice02
详细的介绍可以参考博客:http://blog.csdn.net/adriano119/article/details/5878169
(3)建立bin目录
bin目录下包含以下:
debug目录包含以下:
layout目录下包含以下:
practicecdemo是自己建立的包含.xml文件的目录
这里建立了2个子工程,其中practice01里包含.xml布局文件:
(4)回到src目录,建立2个子工程的cpp文件夹
看其中一个工程的子目录结构
5、建立子工程
(1)添加资源文件theme->practicedemo,如下添加一些工程需要的图片
(2)添加widgets
(3)添加必要的头文件和源文件
stable.h,stable.h.cpp,demoframe.h,demoframe.cpp
(4)添加.pro文件
practice01.pro:
TEMPLATE = app
TARGET = practice01
DEPENDPATH += .
INCLUDEPATH += .
DEFINES += practice01
INCLUDEPATH += ../../../sdk/include
# Input
LIBS += dwutility.lib
LIBS += duifw.lib
LIBS += dwbase.lib
QMAKE_CXXFLAGS -= /MP
PRECOMPILED_HEADER = stable.h
TRANSLATES =practice01.ts
RESOURCES += practice01.qrc
SOURCES += main.cpp
HEADERS += demoframe.h
SOURCES += demoframe.cpp
HEADERS += widgets/demowidget.h
SOURCES += widgets/demowidget.cpp
CONFIG(debug, debug)
{
DESTDIR = ../../bin/debug
QMAKE_LIBDIR += ../../../sdk/lib/debug
}
CONFIG(release, release)
{
DESTDIR = ../../bin/release
QMAKE_LIBDIR += ../../../sdk/lib/release
}
TARGET = practice01
DEPENDPATH += .
INCLUDEPATH += .
DEFINES += practice01
INCLUDEPATH += ../../../sdk/include
# Input
LIBS += dwutility.lib
LIBS += duifw.lib
LIBS += dwbase.lib
QMAKE_CXXFLAGS -= /MP
PRECOMPILED_HEADER = stable.h
TRANSLATES =practice01.ts
RESOURCES += practice01.qrc
SOURCES += main.cpp
HEADERS += demoframe.h
SOURCES += demoframe.cpp
HEADERS += widgets/demowidget.h
SOURCES += widgets/demowidget.cpp
CONFIG(debug, debug)
{
DESTDIR = ../../bin/debug
QMAKE_LIBDIR += ../../../sdk/lib/debug
}
CONFIG(release, release)
{
DESTDIR = ../../bin/release
QMAKE_LIBDIR += ../../../sdk/lib/release
}
(4)添加.qrc文件,用于存放资源图片目录
<RCC>
<qresource>
<file>theme\practicedemo\edit_frame.png</file>
<file>theme\practicedemo\freshMan_greenPeas.png</file>
<file>theme\practicedemo\gambleframe_bk.png</file>
<file>theme\practicedemo\radiobox.png</file>
<file>theme\practicedemo\rect_btn.png</file>
<file>theme\practicedemo\round_btn.png</file>
</qresource>
</RCC>
<qresource>
<file>theme\practicedemo\edit_frame.png</file>
<file>theme\practicedemo\freshMan_greenPeas.png</file>
<file>theme\practicedemo\gambleframe_bk.png</file>
<file>theme\practicedemo\radiobox.png</file>
<file>theme\practicedemo\rect_btn.png</file>
<file>theme\practicedemo\round_btn.png</file>
</qresource>
</RCC>
.qrc文件的详细说明可以参考博客:http://blog.csdn.net/xiaofengkuang/article/details/7262101
(5)添加.ts文件,用于文字的国际化
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0">
<context>
<name>QObject</name>
<message>
<source>Appeal</source>
<translation>申诉</translation>
</message>
</context>
</TS>
<!DOCTYPE TS>
<TS version="2.0">
<context>
<name>QObject</name>
<message>
<source>Appeal</source>
<translation>申诉</translation>
</message>
</context>
</TS>
.ts文件的详细可以参考博客:http://blog.163.com/hu_cuit/blog/static/1228491432011271233383/
(6)添加qm.bat用于生成.ts文件的.qm文件
qm.bat的指令为: lrelease practice01.ts –qm practice01.qm
(7)添加main.cpp
#include "stable.h"
#include "duifw/duiapplication.h"
#include "duifw/duiframewindow.h"
#include "duifw/duixmlui.h"
#include "demoframe.h"
#include "duifw/duilabelwidget.h"
int main(int argc, char *argv[])
{
DuiApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
app.setQuitOnLastWindowClosed( true );
//加载qm文件
QTranslator qTraslator;
QString configFile = QDir::toNativeSeparators(QCoreApplication::applicationDirPath());
configFile = configFile + "/../../src/practice01/practice01.qm";
qTraslator.load(configFile);
app.installTranslator(&qTraslator);
DemoFrame* frame = qobject_cast<DemoFrame*>( DuiXmlUI::createFromFile( "layout/practicedemo/practice01/demoframe.xml", (QWidget*)NULL ) );
frame->setAttribute(Qt::WA_QuitOnClose, true);
//对evenIn的DuiLabelWidget控件修改字体
DuiLabelWidget *label=frame->findChild<DuiLabelWidget *>("evenIn");
if(label)
{
QFont font("Dejavu Sans", 9);
label->setFont(font);
}
frame->show();
return app.exec();
}
#include "duifw/duiapplication.h"
#include "duifw/duiframewindow.h"
#include "duifw/duixmlui.h"
#include "demoframe.h"
#include "duifw/duilabelwidget.h"
int main(int argc, char *argv[])
{
DuiApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
app.setQuitOnLastWindowClosed( true );
//加载qm文件
QTranslator qTraslator;
QString configFile = QDir::toNativeSeparators(QCoreApplication::applicationDirPath());
configFile = configFile + "/../../src/practice01/practice01.qm";
qTraslator.load(configFile);
app.installTranslator(&qTraslator);
DemoFrame* frame = qobject_cast<DemoFrame*>( DuiXmlUI::createFromFile( "layout/practicedemo/practice01/demoframe.xml", (QWidget*)NULL ) );
frame->setAttribute(Qt::WA_QuitOnClose, true);
//对evenIn的DuiLabelWidget控件修改字体
DuiLabelWidget *label=frame->findChild<DuiLabelWidget *>("evenIn");
if(label)
{
QFont font("Dejavu Sans", 9);
label->setFont(font);
}
frame->show();
return app.exec();
}