PDA

View Full Version : How to write Bit and OS specific C++ code?



wizards2020
19th January 2012, 09:58
Hello,

I started a new project in Qt. I want to run my application (final executable) in all platforms and in 32 bit or 64 bit machines.

I am working on 32 bit XP machine and when I try to run on 64 bit Windows 7 the application crashed.

What should I do to run my application in all platforms (all OS's) and 32/64 bit machines?

Should I insert macro like if statements for all Qt API calls?

Can you please give some examples / tutorials to do this?

Thanks
Wizards.

Lesiok
19th January 2012, 13:30
First, you must find the cause of the application crashing in 64 bit platform.
We have a large application that uses a GUI, SQL and RS-232. Application is compiled only in 32-bit mode and is working on Windows XP/Vista/7, Windows Server 2003/2008 both 32 and 64 bits version without any problems.
P.S.
We are using Microsoft Visual C++ not mingw.

stampede
19th January 2012, 14:35
I have a large, Qt based application, compiled on windows server 2003 with mingw. It works without problems on both 32 and 64 bit machines (tested on xp / vista / win 7).
I agree with Lesiok, you have to launch debugger and try to find the cause of this bug.

What should I do to run my application in all platforms (all OS's)
I think you know that already, but in case if you don't - you cannot have "one .exe file to rule them all", you will need to compile one version for mac, one for windows etc.

ChrisW67
19th January 2012, 22:35
I am working on 32 bit XP machine and when I try to run on 64 bit Windows 7 the application crashed.
Compiled, well-behaved code works just fine on Windows XP, Vista or 7 32- or 64-bit. Often problems are arise because the code is not well behaved. For example, a program that assumes it can write files in the same locations as the program exe, or assumes that the user's "My Documents" folder is found under "C:\Document and Settings", will fail on Windows 7. How it fails comes down to how you coded it, but it could crash, behave oddly or, worse, fail in a hidden fashion.

Using Qt makes the majority of your source code completely portable (the binary result is not generally portable). However, there are a few areas where you have differences that you may need to wrap in pre-processor #if blocks (see QtGlobal for macros) or otherwise adapt for environment (e.g. QSysinfo). For example, using the platform specific event filters in QApplication, or code that needs to be aware of byte-order issues, or if your code uses direct access to OS APIs.

wysota
19th January 2012, 23:57
A common and trivial crash pattern when transferring between 32 and 64 bits is to assume that pointers can be cast to 32bit integers.