Qt5.5+VS2013编译的程序在xp下兼容问题解决方法
2015-12-19 02:29
1081 查看
Deploying
Qt on XP and getting “not a valid Win32 application”
By now Windows XP is getting a bit long in the tooth and Microsoft has dropped support for it. Windows 2003, though, is still supported by Microsoft. If you’ve using Qt together with Visual Studio (and not
the MinGW compiler) and you try deploying your app to a Windows XP or Windows Server 2003 computer, chances are you’re seeing this error:
Too far from the future?
This error will not occur for Qt with Visual Studio 2010, but it will when using Visual Studio 2012, 2013 or Visual Studio 2015.
Update thanks to comment below: (use QMAKE_LFLAGS_WINDOWS instead of tweaking the project’s setting):There are basically two ways to fix this; the easy way is to add one extra line to your project’s
.pro file, or you can be more adventurous and binary-patch your app’s .exe file.
And yes, this has to be applied for every app you develop, until XP is gone gone gone…
Note: This same error (“.. not a valid Win32 application.”) occurs if you try to start a 64-bit app on a 32-bit Windows XP or Windows 2003 system, so make sure your app is really 32-bit flavored.
One way to verify the bitness: launch your app in Windows 7 or 10, start Task Manager, in the process tab check that your app’s name has a “* 32” suffix.
Also: This tweaking do not affect or disturb deployment to other, later Windows versions like Windows 7. (In case you’re targeting multiple Windows versions.) I have verified this works on
Windows XP Service Pack 3 and Windows Server 2003 Service Pack 1 and 2 systems.
Let’s take them in order:
Open the .pro file for your project and insert this line (I usually do it at the end):
Why 5.01? Well if you look at the original settings, using for example
your .exe file, you see that the SUBSYSTEM:WINDOWS version is set to 6. This means it can run on Windows Vista and later and why Windows XP rejects it. By changing it to 5, we declare XP and Win2k3 as kosher chaps too. (Those numbers 5 and 6 are the internal
Windows version numbers.)
I thought originally it should be enough to specify /SUBSYSTEM:WINDOWS,5 but then the linker complains: LNK4010: invalid subsystem version number, and it resets it back to 6
So
5.01 it is.
Note: if you’re compiling a 64-bits flavored .exe file (and thus targeting 64-bits Windows XP) you instead should set <VALUE> to /SUBSYSTEM:WINDOWS,5.02
I promised you a more thrilling choice as well, it requires you to have a binary/hex file editor. Open your app’s .exe file with it, go to almost the beginning of the file, you’ll see something along the following
lines:
Before the binary editing
Look for the hex sequence 06 00 00 00 00 00 00 00 (repeated one time). In my example above it’s on address 0000130 but it can be slightly different like 0000128 or 0000140.
After the binary editing
There’s two consecutive series, change both of them to 05 00 01 00 00 00 00 00.
This binary editing is equivalent to the linker setting I mention above, but actually it suffices to change the two 06 numbers to 05. However, the linker complained when I tried SUBSYSTEM:WINDOWS,5, so let’s
humor Microsoft here and set the binary numbers equivalent to SUBSYSTEM:WINDOWS,5.01
Note: if this a 64-bit .exe file, you’re supposed to instead change to 05 00 02 00 00 00 00 00 (two times).
Save the .exe file, Windows XP and Win2k3 server should run the file fine.
转载自:http://www.tripleboot.org/?p=423
Qt on XP and getting “not a valid Win32 application”
By now Windows XP is getting a bit long in the tooth and Microsoft has dropped support for it. Windows 2003, though, is still supported by Microsoft. If you’ve using Qt together with Visual Studio (and not
the MinGW compiler) and you try deploying your app to a Windows XP or Windows Server 2003 computer, chances are you’re seeing this error:
Too far from the future?
This error will not occur for Qt with Visual Studio 2010, but it will when using Visual Studio 2012, 2013 or Visual Studio 2015.
Update thanks to comment below: (use QMAKE_LFLAGS_WINDOWS instead of tweaking the project’s setting):There are basically two ways to fix this; the easy way is to add one extra line to your project’s
.pro file, or you can be more adventurous and binary-patch your app’s .exe file.
And yes, this has to be applied for every app you develop, until XP is gone gone gone…
Note: This same error (“.. not a valid Win32 application.”) occurs if you try to start a 64-bit app on a 32-bit Windows XP or Windows 2003 system, so make sure your app is really 32-bit flavored.
One way to verify the bitness: launch your app in Windows 7 or 10, start Task Manager, in the process tab check that your app’s name has a “* 32” suffix.
Also: This tweaking do not affect or disturb deployment to other, later Windows versions like Windows 7. (In case you’re targeting multiple Windows versions.) I have verified this works on
Windows XP Service Pack 3 and Windows Server 2003 Service Pack 1 and 2 systems.
Let’s take them in order:
Open the .pro file for your project and insert this line (I usually do it at the end):
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
Why 5.01? Well if you look at the original settings, using for example
dumpbin/headerson
your .exe file, you see that the SUBSYSTEM:WINDOWS version is set to 6. This means it can run on Windows Vista and later and why Windows XP rejects it. By changing it to 5, we declare XP and Win2k3 as kosher chaps too. (Those numbers 5 and 6 are the internal
Windows version numbers.)
I thought originally it should be enough to specify /SUBSYSTEM:WINDOWS,5 but then the linker complains: LNK4010: invalid subsystem version number, and it resets it back to 6
So
5.01 it is.
Note: if you’re compiling a 64-bits flavored .exe file (and thus targeting 64-bits Windows XP) you instead should set <VALUE> to /SUBSYSTEM:WINDOWS,5.02
I promised you a more thrilling choice as well, it requires you to have a binary/hex file editor. Open your app’s .exe file with it, go to almost the beginning of the file, you’ll see something along the following
lines:
Before the binary editing
Look for the hex sequence 06 00 00 00 00 00 00 00 (repeated one time). In my example above it’s on address 0000130 but it can be slightly different like 0000128 or 0000140.
After the binary editing
There’s two consecutive series, change both of them to 05 00 01 00 00 00 00 00.
This binary editing is equivalent to the linker setting I mention above, but actually it suffices to change the two 06 numbers to 05. However, the linker complained when I tried SUBSYSTEM:WINDOWS,5, so let’s
humor Microsoft here and set the binary numbers equivalent to SUBSYSTEM:WINDOWS,5.01
Note: if this a 64-bit .exe file, you’re supposed to instead change to 05 00 02 00 00 00 00 00 (two times).
Save the .exe file, Windows XP and Win2k3 server should run the file fine.
转载自:http://www.tripleboot.org/?p=423
相关文章推荐
- Qt之Tab键切换焦点顺序
- Qt之Tab键切换焦点顺序
- Qt中的对象类型转换
- Qt之重启应用程序
- Qt之重启应用程序
- QTabWiget Change Color 改变颜色(每个QWidget都有一个自己的调色板palette,设置它的颜色,然后setAutoFillBackground即可)
- 使用Qt 开发图形界面的软件
- Qt SizePolicy 属性
- QT5.x incomingConnection不能被调用的解决方案
- QT 获取焦点失去焦点事件
- QT窗口置顶
- QT学习笔记
- QSettings的用法详解(读Qt creator帮助文档自己理解 )
- Magento 查询订单 和 该笔总的qty
- Qt之密码框不可选中、复制、粘贴、无右键菜单等
- Qt之密码框不可选中、复制、粘贴、无右键菜单等
- 基于QT的在线打字练习软件助手(C/S模型)
- QThread使用——关于run和movetoThread的区别
- Magento 获取 头一天的订单里的产品的qty_ordered
- Qt事件总结(鼠标、键盘)