Important: Please read the Qt Code of Conduct -

How to call ui->show(); from other file

  • int main(int argc, char *argv[])
    QApplication a(argc, argv);

     QSurfaceFormat format;
     //antializing samples
     TriangleWindow window;
     window.resize(900, 700);
     window.setAnimating(true);;  //gl
     MainWin m_win;;       //ui
     timer_class tim;
    return a.exec();


    How to call ui->show(); from other file?

    Cannot declare extern and place MainWin m_win before main() it crashes app.
    Also would be good if QSurfaceFormat format; acessible by other files.

  • I guess the ui->show() you're referring to is the one from the designer part of your MainWin class. Why don't you add a method in MainWin which internally callsui->show()?

  • Can you please describe in more detail , my programming vocabulary not very good.

  • Well, your question is not so clear as well. I'll try again.

    I guess the ui you're talking about is declared in the MainWin header fil e. Then what I told you is IF you need to be able to call ui->show, you could add a method in MainWin class, which would internally call ui->show. However, I don't think this is usefull, as calling MainWin::show() calls show for the ui component.

    I have no clue about which QSurfaceFormat instance you're talking about. I don't have any crystal ball, therefore it's hard to tell.

  • Very sorry, i was not aware that you are not having big crystal ball.
    Would like to be able to call TriangleWindow and mainwin from eachother to respawn closed window.

  • Lifetime Qt Champion

    Hi your idea with extern should be able to work.
    Just use pointers and it will work.

    in "TriangleWindow.h"
    extern TriangleWindow *MyTW;
    and have it defined in the .cpp

    and then in main
    MyTW=new TriangleWindow();
    Then in other file , say mainwindow you can include
    TriangleWindow .h and have access via
    This is of course global variables and might
    not be the most elegant way of handling it.

    QSurfaceFormat format;
    This only lives in main and you must move it as only main can see it.

Log in to reply