C ++ - Qt - Visual Studio 2010 - 应用程序与gui和控制台 [英] C++ - Qt - Visual Studio 2010 - application with both gui and console

查看:115
本文介绍了C ++ - Qt - Visual Studio 2010 - 应用程序与gui和控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有为程序提供参数,它将作为GUI应用程序启动,如果给定args,则通过命令行运行。我能够得到visual studio来显示和打印到控制台与属性>链接器>子系统(控制台/ SUBSYSTEM:CONSOLE),但这使得控制台总是显示,当应用程序启动时,我如何选择性地显示控制台,以便当应用程序运行与GUI它不会出现。我已经浏览了网站,但我所找到的是如何设置它只是一个Windows应用程序,我需要它作为

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 display and print to the console with Properties>Linker>SubSystem (Console/SUBSYSTEM:CONSOLE), but this makes it so that the console always displays when the application is launched, how can I selectively display the console so that when the app is run with the GUI it does not appear. I have looked through the site, but all I have found is how to set it to only be a windows application, and I need it to function as both

推荐答案

这个作品我想:

#include <QtGui/QApplication>
#include <QtGui/QMainWindow>


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.

这篇关于C ++ - Qt - Visual Studio 2010 - 应用程序与gui和控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆