Results 1 to 5 of 5

Thread: How to write Bit and OS specific C++ code?

  1. #1
    Join Date
    Jan 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How to write Bit and OS specific C++ code?

    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.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write Bit and OS specific C++ code?

    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.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to write Bit and OS specific C++ code?

    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to write Bit and OS specific C++ code?

    Quote Originally Posted by wizards2020 View Post
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write Bit and OS specific C++ code?

    A common and trivial crash pattern when transferring between 32 and 64 bits is to assume that pointers can be cast to 32bit integers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to write code for the fibonacci series in Qt?
    By harish in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2011, 05:28
  2. Replies: 0
    Last Post: 31st October 2011, 05:01
  3. Replies: 10
    Last Post: 15th August 2011, 22:26
  4. how to write QT openGL code in two classes
    By qtUse in forum Qt Programming
    Replies: 8
    Last Post: 31st August 2010, 06:41
  5. Replies: 5
    Last Post: 15th March 2006, 08:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.