How I show application when open application again Qt

前端 未结 2 1651
闹比i
闹比i 2021-01-19 02:06

Now, I have 1 application, but I don\'t want to open application twice, so I using QShareMemory to detect application when open twice. And my question is: how I

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-19 02:59

    Just use QSingleApplication class instead of QApplication: https://github.com/qtproject/qt-solutions/tree/master/qtsingleapplication

    int main(int argc, char **argv)
    {
        QtSingleApplication app(argc, argv);
        if (app.isRunning())
            return 0;
    
        MyMainWidget mmw;
        app.setActivationWindow(&mmw);
        mmw.show();
    
        return app.exec();
    }
    

    It is part of Qt Solutions: https://github.com/qtproject/qt-solutions

提交回复
热议问题