一个用纯C++实现的MVVM Light框架,Qt仅作为界面层,提供C#风格的发布订阅模式。
- ✅ C#风格的事件系统
- ✅ 属性变更通知
- ✅ 命令模式
- ✅ 消息传递
- ✅ 资源清理
- ✅ Qt集成
- ✅ 跨平台支持
- C++17/20
- Qt6 (仅用于界面)
- CMake构建系统
cppmvvm/
├── include/MvvmLight/ # 头文件
├── src/ # 源文件
├── examples/ # 示例代码
├── tests/ # 单元测试
└── docs/ # 文档
#include "MvvmLight/core/ViewModelBase.hpp"
#include "MvvmLight/commands/RelayCommand.hpp"
class MainViewModel : public MvvmLight::ViewModelBase {
public:
MainViewModel() {
buttonCommand_ = std::make_shared<MvvmLight::RelayCommand>(
[this]() { onButtonClicked(); }
);
}
const std::string& title() const { return title_; }
void setTitle(const std::string& title) {
setProperty(title_, title, "Title");
}
std::shared_ptr<MvvmLight::ICommand> buttonCommand() const {
return buttonCommand_;
}
private:
void onButtonClicked() {
setTitle("Button Clicked!");
}
std::string title_ = "Hello World";
std::shared_ptr<MvvmLight::ICommand> buttonCommand_;
};mkdir build
cd build
cmake ..
makeMIT License