How to use local static variables when Qt creates a new window

When creating a sub-interface in the main interface, we usually create a pointer to the sub-window in the header file beforehand, and then initialize it where needed, which is not very convenient. So I tried to create a static pointer and it felt better. As shown in the figure below, the address of the pointer remains unchanged every time you click show to display the child window. Prove that this is feasible.

void Network::slotSetIp()
{
    
    
    qDebug()<<__FUNCTION__;
    static NetworkConfig* networkConfig = new NetworkConfig();
    qDebug("%p\n",networkConfig);

    networkConfig->setWindowModality(Qt::ApplicationModal);
    networkConfig->show();
}

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/poolooloo/article/details/108387415