-----------qt-----------C++的模板的使用, ---定义一个模块类--------
2014-01-09 10:44
609 查看
转自:http://qt-project.org/forums/viewthread/14782
If we’re throwing around solutions anyway: you could even create a class template that adds this function to any widget you want, including all stock widgets. :-)
template <class T>
public IDClass<T>: public T {
public:
IDClass(int id, QWidget* parent = 0):
m_id(id),
T(parent)
{}
void setId(int newId) {m_id = newId};
int id() const {return m_id;}
private:
int m_id;
}
typedef IDClass<QLineEdit> IdLineEdit;
typedef IDClass<QPushButton> IdPushButton;
//etc.
If we’re throwing around solutions anyway: you could even create a class template that adds this function to any widget you want, including all stock widgets. :-)
template <class T>
public IDClass<T>: public T {
public:
IDClass(int id, QWidget* parent = 0):
m_id(id),
T(parent)
{}
void setId(int newId) {m_id = newId};
int id() const {return m_id;}
private:
int m_id;
}
typedef IDClass<QLineEdit> IdLineEdit;
typedef IDClass<QPushButton> IdPushButton;
//etc.
相关文章推荐
- 一个使用sbt编译的JNI C++ 的模板
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- requirejs如何使用define定义一个模块
- C++库研究笔记——使用函数模板还是类模板?+ 一个类型重复问题的两种解决方法
- requirejs如何使用define定义一个模块
- C++基础之两个头文件使用同一个变量会重复定义怎么办
- requirejs如何使用define定义一个模块
- 使用layui定义一个模块并使用的实例
- requirejs如何使用define定义一个模块
- C++ 使用模板实现一个List的实例
- C++在使用Qt中SLOT宏需要注意的一个小细节
- C++在使用Qt中SLOT宏需要注意的一个小细节
- requirejs如何使用define定义一个模块
- C++ 异常机制分析(C++标准库定义了12种异常,很多大公司的C++编码规范也是明确禁止使用异常的,如google、Qt)