简体   繁体   English

Qt,从另一个子窗口小部件获取子窗口小部件内的数据

[英]Qt, get data inside a child widget from another child widget

I create new cad widget in my mainwindow: 我在主窗口中创建新的cad小部件:

glWidget = new MeshViewerWidget(this);

and then my text view widget: 然后是我的文本视图小部件:

tbl = new tableView( this );

in my mainwindow i can get my mesh with: 在我的主窗口中,我可以使用以下方法进行网格划分:

glWidget->mesh();

How do i get it in my tableview.cc? 我如何在tableview.cc中获取它? ty ty

You could use the findChildren function of QObject and get a list of all children of a widget that can be casted to the given type. 您可以使用QObjectfindChildren函数并获取可转换为给定类型的小部件的所有子级的列表。 Eg 例如

QList<QTableView*> allTableViews = glWidget->findChildren<QTableView *>();
// Iterate in order to find the table view either by checking the name, the parent etc....

Another approach would be the one Simon suggests, subclassing and adding public access function to the members you want to be reachable from top level widgets. Simon提出的另一种方法是,将子类添加到公共控件中,然后将其添加到您希望从顶层小部件可访问的成员。

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

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