Qt中子窗口获取顶层窗口、顶层窗口获取子窗口的方法

    foreach(QWidget *win,qApp->topLevelWidgets())
    {
        if(MainWindow *mainWin=qobject_cast(win))
        {
            mainWin->test();
        }
    }

 

    QMdiSubWindow *sub=ui->mdiArea->activeSubWindow();
    QWidget *subwin=sub->widget();//这段容易出错,必须调用widget()
    SubText *subWindow=(SubText*)subwin;
    if(subWindow==NULL)
    {
        return;
    }
    subWindow->print();

 

你可能感兴趣的:(C/C++,Qt)