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

查看:54
本文介绍了为什么我的 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 测试库会导致控制台出现.删除它会使它消失.

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 debugMyApp.exe object_script.MyApp.Debug  
   -L"c:Qt2009.01qtlib"  
   -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 debugAmmotin.exe object_script.Ammotin.Debug  
   -L"c:Qt2009.01qtlib" 
   -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtWebKitd4 
   -lQtSqld4  -lQtGuid4 -lQtNetworkd4 -lQtCored4

耶!子系统是窗口,没有更多的控制台窗口.

Yay! subsystem is windows, no more console window.

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

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