从 Qt 脚本访问非基于 QObject 的对象

发布于 2024-08-25 20:05:38 字数 319 浏览 6 评论 0原文

有没有什么好的简单方法可以从 Qt 脚本访问非基于 QObject 的类,例如 QXmlQuery、QDateTime 等?

我看到的唯一方法是将 QXmlQuery 包装在另一个继承 QObject 的类中,并将我需要从 Qt 脚本访问的每个函数声明为插槽:

void MyXmlQuery::setQuery ( const QString & sourceCode, const QUrl & documentURI )
{
    realxmlquery_.setQuery(sourceCode, documentURI);
}

Is there any nice and simple way to access non QObject-based classes, such as QXmlQuery, QDateTime etc. from Qt Script?

The only way I see is to wrap QXmlQuery in another class that inherits QObject and declare as slot every function which I need to access from Qt Script:

void MyXmlQuery::setQuery ( const QString & sourceCode, const QUrl & documentURI )
{
    realxmlquery_.setQuery(sourceCode, documentURI);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-09-01 20:05:38

创建一个接口类来完成这项工作。

void MyXmlQuery::setQuery ( const QString & sourceCode, const QUrl & documentURI )
{
    this->realxmlquery_->setQuery(sourceCode, documentURI); //realxmlquery is a reference to the Non-qt class!
}

create a interface class to do this job.

void MyXmlQuery::setQuery ( const QString & sourceCode, const QUrl & documentURI )
{
    this->realxmlquery_->setQuery(sourceCode, documentURI); //realxmlquery is a reference to the Non-qt class!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文