C++ - Qt - Visual Studio 2010 - application with both gui and console

前端 未结 3 2058
名媛妹妹
名媛妹妹 2021-01-01 07:14

If no arguments are given to the program it launches as a GUI application, if it is given args it is run through the command line. I was able to get visual studio to displa

3条回答
  •  感动是毒
    2021-01-01 07:59

    This works I guess:

    #include 
    #include 
    
    
    int
    main(int n_app_args, char **app_arg)
    {
        QCoreApplication * application = 0;
    
        if ( n_app_args == 1 )
        {
            application = new QCoreApplication(n_app_args, app_arg);
        }
        else
        {
            application = new QApplication(n_app_args, app_arg);
            QMainWindow * mainWindow = new QMainWindow();
            mainWindow->show();
        }
    
    
        return application->exec();
    }
    

    Call it with an argument and you get a little (empty) window. Call it with no argument and no window.

提交回复
热议问题