为什么我的Qt 4.5应用程序在Windows下打开控制台窗口? [英] Why does my Qt 4.5 app open a console window under Windows?

查看:225
本文介绍了为什么我的Qt 4.5应用程序在Windows下打开控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Linux下的Qt Creator 4.5.我的应用程序在Linux下可以很好地构建,但是如果我在Windows中构建,则该应用程序总是在启动时打开控制台窗口.

I've been playing around with Qt Creator 4.5 under Linux. My application builds just fine under Linux, but if I build in Windows, the app always opens a console window at startup.

我可以停止这样做吗?

我正在使用默认的MinGW设置进行构建,也许与此有关.如果需要,我可以使用Visual Studio进行构建,但是我想先了解发生了什么...

I'm building using the default MinGW setup, perhaps that is related. If need be I can build with Visual Studio, but I'd like to understand what is happening first...

编辑:我只是在Windows下使用Qt Creator创建了一个简单的测试GUI应用程序,但没有表现出这种行为.由于在linux下创建项目的方式而发生了这种现象,或者我的应用程序执行了某些操作导致控制台窗口出现.我会在诊断时发布详细信息,以防其他人使用.

Edit: I just created a simple test GUI app with Qt Creator under Windows and it didn't exhibit this behaviour. Either this behaviour has occurred because of the way the project was created under linux, or there is something my app does which causes the console window to appear. Will post details when I diagnose it in case it helps someone else.

推荐答案

简短的答案是,包括Qt testlib会导致控制台出现.删除它会使它消失.

The short answer is that including the Qt testlib causes the console to appear. Removing it makes it go away.

要进一步说明,例如,.pro文件是否将testlib添加到QT中,例如

To explain further, if your .pro file adds testlib to QT, e.g.

QT += sql \
    webkit \
    network \
    testlib

然后使用这样的一行执行最后的链接步骤

then the final link step is carried out with a line like this

g++ -enable-stdcall-fixup 
   -Wl,-enable-auto-import 
   -Wl,-enable-runtime-pseudo-reloc 
   -mthreads 
   -Wl 
   -Wl,-subsystem,console 
   -o debug\MyApp.exe object_script.MyApp.Debug  
   -L"c:\Qt\2009.01\qt\lib"  
   -lglu32 -lgdi32 -luser32 -lQtWebKitd4 -lQtTestd4 
   -lQtSqld4 -lQtGuid4 -lQtNetworkd4 -lQtCored

我们已经结束了使用控制台子系统的工作!我认为使用testlib会强制这种情况发生,以便测试输出有待解决的地方.

We've wound up using the console subsystem! I presume using testlib forces this to happen so that the test output has somewhere to go.

如果我们现在编辑.pro文件并删除对testlib的引用并进行重建,则会得到这样的链接步骤

If we now edit the .pro file and remove the reference to testlib and rebuild, we get a link step like this

g++ -enable-stdcall-fixup 
   -Wl,-enable-auto-import 
   -Wl,-enable-runtime-pseudo-reloc 
   -mthreads 
   -Wl 
   -Wl,-subsystem,windows 
   -o debug\Ammotin.exe object_script.Ammotin.Debug  
   -L"c:\Qt\2009.01\qt\lib" 
   -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtWebKitd4 
   -lQtSqld4  -lQtGuid4 -lQtNetworkd4 -lQtCored4

是的!子系统是Windows,不再是控制台窗口.

Yay! subsystem is windows, no more console window.

这篇关于为什么我的Qt 4.5应用程序在Windows下打开控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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