简体   繁体   English

Qt5:从插件中调用主应用程序功能

[英]Qt5: Call main-application functions from within a plugin

I am currently messing around with plugins in Qt5 (QPlugin). 我目前正在搞乱Qt5(QPlugin)中的插件。 More specifically I have been looking into this example: 更具体地说,我一直在研究这个例子:

https://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html https://doc.qt.io/qt-5/qtwidgets-tools-echoplugin-example.html

There they create an abstract interface class to access functions in the plugin. 在那里,他们创建了一个抽象接口类来访问插件中的函数。 Now here comes the question: Does this work the other way around? 现在问题在于:这是否相反?

Say I do stuff in my plugin and want to print some results to a GUI which lives in the main application. 假设我在我的插件中做了一些事情,并希望将一些结果打印到主应用程序中的GUI。 Can I call GUI functions from within the plugin? 我可以在插件中调用GUI函数吗? Or is there another way to achieve this kind of communication from plugin to application? 或者是否有另一种方法可以实现从插件到应用程序的这种通信?

Messed a bit around and... 稍微弄清楚......

Answer was, to simply send the Main GUI's pointer as parameter of one of the interface functions and storing that pointer in the plugin class. 回答是,简单地将Main GUI的指针作为其中一个接口函数的参数发送,并将该指针存储在插件类中。 That way, you can access the GUI (and other classes in the main application) from within the plugin. 这样,您就可以从插件中访问GUI(以及主应用程序中的其他类)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM