Results 1 to 9 of 9

Thread: QT Creator, cross platform program.

  1. #1
    Join Date
    Dec 2008
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QT Creator, cross platform program.

    Hello.

    I have a small problem with QT Creator. Program will be run on Windows and Linux platform. I don't have problems on Linux but I have some on Windows. All the platform dependent parts of program I would put in #define test:
    Qt Code:
    1. #ifdef unix
    2. #include "*****.h"
    3. #endif
    4. #ifdef win32
    5. #warning "Macro defined win32"
    6. #include "******.h"
    7. #else
    8. #warning "Macro not defined win32"
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    I found in doc.
    For projects that need to be built differently on each target platform, with many subdirectories, you can run qmake with each of the following options to set the corresponding platform-specific variable in each project file:
    -unix
    qmake will run in unix mode. In this mode, Unix file naming and path conventions will be used, additionally testing for unix (as a scope) will succeed. This is the default mode on all Unices.
    -macx
    qmake will run in Mac OS X mode. In this mode, Unix file naming and path conventions will be used, additionally testing for macx (as a scope) will succeed. This is the default mode on Mac OS X.
    -win32
    qmake will run in win32 mode. In this mode, Windows file naming and path conventions will be used, additionally testing for win32 (as a scope) will succeed. This is the default mode on Windows.
    I don't have any idea why is not working on Windows.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QT Creator, cross platform program.

    You've mistaken macros with qmake scopes. See Q_OS_* and Q_WS_* definitions in QtGlobal header.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    kazek3018 (15th December 2008)

  4. #3
    Join Date
    Dec 2008
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT Creator, cross platform program.

    Thanks.

    Now I got another problem, program is compiling and I get error from linker.
    undefined reference to `TWinClass::TWinClass()'
    Class structure is look like:
    Qt Code:
    1. class TBaseClass
    2. {};
    3.  
    4. TLinuxClass: public TBaseClass
    5. {};
    6.  
    7. TWinClass: public TBaseClass
    8. {};
    To copy to clipboard, switch view to plain text mode 

    in main.cpp i have this:
    Qt Code:
    1. #ifdef Q_WS_X11
    2. #include "tlinuxclass.h"
    3. #endif
    4. #ifdef Q_WS_WIN
    5. #include "twinclass.h"
    6. #endif
    7.  
    8. .....
    9. TBaseClass *Base;
    10. #ifdef Q_WS_X11
    11. Base=new TLinuxClass;
    12. #endif
    13. #ifdef Q_WS_WIN
    14. Base=new TWinClass;
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Any idea?

    Edit --------------------------------------------------
    On Linux I got the same error from linker. If I change #ifdef Q_WS_X11 to #ifdef unix, then every thing is ok.
    Edit2 -------------------------------------------------------
    The same situation is with Q_OS_LINUX.
    Last edited by kazek3018; 15th December 2008 at 21:49.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QT Creator, cross platform program.

    Sounds like TWinClass constructor is declared but not implemented. How about declaring the whole class once and just providing different implementation for it in different files:
    Qt Code:
    1. // myclass.h:
    2. class MyClass
    3. {
    4. public:
    5. MyClass();
    6. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // myclass_unix.cpp:
    2. #include "myclass.h"
    3.  
    4. MyClass::MyClass()
    5. {
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // myclass_win.cpp:
    2. #include "myclass.h"
    3.  
    4. MyClass::MyClass()
    5. {
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    In that case your .pro file would look like this:
    Qt Code:
    1. HEADERS += myclass.h
    2. unix:SOURCES += myclass_unix.cpp
    3. win32:SOURCEs += myclass_win.cpp
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #5
    Join Date
    Dec 2008
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT Creator, cross platform program.

    All the class has it own file.

    My .pro file is made by QT Creator. All Linux platform depended code is in
    Qt Code:
    1. //#ifdef Q_OS_LINUX
    2. //#ifdef Q_WS_X11
    3. #ifdef unix
    To copy to clipboard, switch view to plain text mode 

    and now, everything is ok when I test for unix, but when I testing for Q_OS_LINUX or Q_WS_X11 then I got error from linker.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QT Creator, cross platform program.

    "unix", "win32" etc. scopes provided by qmake are used in qmake project files, not in source files. In source files you are supposed to use those Q_* macro definitions. And if you follow my example, you don't need to test macros at all because only appropriate files are compiled for each platform.
    J-P Nurmi

  8. #7
    Join Date
    Dec 2008
    Posts
    13
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT Creator, cross platform program.

    Thanks, now I understand the qmake scopes.

    I don't really want to resign from Q_* macros and do it in your way because it will generate to many job for me. Now every thing work ok.

  9. #8
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Creator, cross platform program.

    I tried QT Creator for awhile yesterday. I still like QDevelop (qdevelop.org) better; but that may be because I'm used to it.

    Karl

  10. #9
    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: QT Creator, cross platform program.

    Quote Originally Posted by kazek3018 View Post
    I don't really want to resign from Q_* macros and do it in your way because it will generate to many job for me.
    It is very unlikely you are correct with this statement. If you follow what jpn said, you will make a modification in one place only instead of inserting defines everywhere you need to do something not cross-platform. It is much much easier to maintain code if you have everything platform-dependent in one place.

Similar Threads

  1. Crash handler on Win32
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 19:41
  2. Detect platform where my QT4 program is running on
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 12:01
  3. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19

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.