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

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

问题描述

我一直在Linux下使用Qt Creator 4.5。我的应用程序在Linux下构建正常,但如果我在Windows中构建,应用程序总是在启动时打开一个控制台窗口。



我可以停止它吗? >

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



编辑:我只是在Windows下使用Qt Creator创建了一个简单的测试GUI应用程序,它没有展示这种行为。这种行为发生了,因为在linux下创建项目的方式,或有一些我的应用程序,导致控制台窗口出现。

解决方案

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



要进一步解释,如果.pro文件将testlib添加到QT,例如

  QT + = sql \ 
webkit \
network \
testlib

$ b b

那么最后的链接步骤就是用这样的一行来执行的。

  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
-Lc:\Qt\2009.01\qt\lib
-lglu32 -lgdi32 -luser32 -lQtWebKitd4 -lQtTestd4
-lQtSqld4 -lQtGuid4 -lQtNetworkd4 -lQtCored

绕过使用控制台子系统!我认为使用testlib强制这发生,以便测试输出有某个地方去。



如果我们现在编辑.pro文件并删除对testlib的引用并重建,我们将获得如下的链接步骤

  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
-Lc:\Qt \2009.01\qt\lib
-lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtWebKitd4
-lQtSqld4 -lQtGuid4 -lQtNetworkd4 -lQtCored4

Yay!子系统是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.

Can I stop it doing that?

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...

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.

解决方案

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

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

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.

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

Yay! subsystem is windows, no more console window.

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

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