简体   繁体   English

Qt QWidget多个实例

[英]Qt QWidget multiple instances

We are multiple people working on one Qt app. 我们是一个Qt应用程序上的多个人。 I for one am implementing a library, which will be instanciated in multiple other parts of the app. 我正在实施一个库,该库将在应用程序的其他多个部分中实例化。 This library has a display class+form along with it. 该库具有显示类+表单。

Until now I had simply created one single instance of the library, running on a dummy, and passed debug data to one instance of the display+form, and worked like that. 到现在为止,我只创建了一个库的单个实例,在一个虚拟对象上运行,然后将调试数据传递到display + form的一个实例,并以此方式工作。

But now that core debugging is finished, goal is to have everything instantiable - not just the core library code, but also the form itself, and embed that form into other displays. 但是,既然核心调试已完成,目标是使所有实例均可实例化-不仅是核心库代码,还包括表单本身,并将该表单嵌入到其他显示中。 Each caller/user would be reponsible for passing output data of the core library instance they are using to an instance of the form. 每个调用者/用户将负责将他们正在使用的核心库实例的输出数据传递给表单的实例。 Each instance of the form would separately display the information generated by a specific library instance, possibly with different display options - they are all independent. 表单的每个实例将分别显示由特定库实例生成的信息,可能具有不同的显示选项-它们都是独立的。

Similarly, it is possible to enter values in my display. 同样,可以在我的显示中输入值。 Goal is to be able to enter different values in different displays instantiated accross the app, and sending those to specific instances (caller's responsiblity). 目标是能够在整个应用程序实例化的不同显示中输入不同的值,并将这些值发送到特定实例(调用者的责任)。

Question is of course : how to do that ? 问题当然是:该怎么做? Internet talks about promoting, but I still don't see anywhere in Qt Designer where to include so-called promoted objects in other objects. 互联网谈论提升,但是我仍然没有在Qt Designer的任何地方看到在其他对象中包含所谓的提升对象。

TL;DR : : I want some existing form to appear in the menu on the left in Qt Designer to be able to instantiate it multiple times in other forms. TL; DR ::我希望一些现有的形式出现在Qt Designer的左侧菜单中,以便能够以其他形式多次实例化它。 How to do this ? 这个怎么做 ?

Thanks in advance for the help ! 先谢谢您的帮助 !

Charles 查尔斯

You can promote any QWidget to your control from within Qt Designer. 您可以从Qt Designer QWidget任何QWidget提升为控件。 Add a QWidget , right-click and promote. 添加一个QWidget ,右键单击并升级。

Ideally, you should create a designer plugin for your control, make the relevant properties designable, and build the plugin as well as the library. 理想情况下,您应该为控件创建一个设计器插件,使相关属性可设计,并构建该插件和库。 That way you'll be able to drag your control from the palette, and it will behave like the real thing. 这样,您就可以将控件从调色板中拖出,并且其行为将与真实情况一样。

Qt QWidget multiple instances Qt QWidget多个实例

You answered yourself. 你回答了你自己。 Qt Creator: "File->New->Qt->Qt Designer Form Class" with QWidget as a base class will suit you. Qt Creator:以QWidget为基类的“文件->新建-> Qt-> Qt Designer表单类”将适合您。 Then you can promote a simple QWidget in the UI into this custom widget, to create an instance. 然后,您可以在用户界面中将简单的QWidget提升为该自定义窗口小部件,以创建实例。 Each instance will manage its own UI. 每个实例将管理自己的UI。

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

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