我在主窗口中创建新的cad小部件:

glWidget = new MeshViewerWidget(this);


然后是我的文本视图小部件:

tbl = new tableView( this );


在我的主窗口中,我可以使用以下方法进行网格划分:

glWidget->mesh();


我如何在tableview.cc中获取它? ty

最佳答案

您可以使用findChildrenQObject函数,并获取可转换为给定类型的小部件的所有子级的列表。例如

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


西蒙建议的另一种方法是,将顶级类中的公共访问功能子类化并添加到您希望可以访问的成员中。

10-07 19:16
查看更多