gpt4 book ai didi

c++ - QML 新手在将 C++ 后端与 QML 前端连接起来时需要一些帮助

转载 作者:行者123 更新时间:2023-11-30 02:06:03 29 4
gpt4 key购买 nike

我有 C++ 代码,用于从 XML 文件保存和检索数据。我有一些内置在 QML 中的表单,我想以这样一种方式连接:当在我的 QML 中输入数据时,处理在 C++ 中处理,并通过 QML 表单搜索产品,在 C++ 中处理和产品列表项目被交还给 QML 进行展示。

class ProcessRequests : public QObject
{
Q_OBJECT
Q_PROPERTY(string username READ username WRITE username)
Q_PROPERTY(string useremail READ useremail WRITE useremail)
Q_PROPERTY(string usercomplaint READ usercomplaint WRITE usercomplaint)


public:

ProcessRequests()
{}
~ProcessRequests(){}

Q_INVOKABLE void SubmitComplaint(){
//TODO: Add Xml code to save the property values to file

}

};

最佳答案

我认为你的问题是 QML 和 C++ 代码之间的相互通信,你可以用这样的代码来做到这一点:

//Product.cpp
QmlApplicationViewer viewer;

QDeclarativeEngine *engine = viewer.engine();
QDeclarativeContext *context = engine->rootContext();

context->setContextProperty("Product", this);

//Your QML File
Product.YourFunction(args);

关于c++ - QML 新手在将 C++ 后端与 QML 前端连接起来时需要一些帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136086/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com