Results 1 to 6 of 6

Thread: Porting HelloWorld Qt Application from WINDOWS to LINUX

  1. #1
    Join Date
    Feb 2011
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Porting HelloWorld Qt Application from WINDOWS to LINUX

    Hello,

    Could some one tell me the step by step procedure to cross compile the "HelloWorld" Qt App from Windows to Linux.

    Regards,
    Sankar.

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Porting HelloWorld Qt Application from WINDOWS to LINUX

    Hi,

    Im guessing the hello world example is:

    main.cpp
    Qt Code:
    1. include <qapplication.h>
    2. include <qpushbutton.h>
    3.  
    4. int main( int argc, char **argv )
    5. {
    6. QApplication a( argc, argv );
    7.  
    8. QPushButton hello( "Hello world!", 0 );
    9. hello.resize( 100, 30 );
    10.  
    11. a.setMainWidget( &hello );
    12. hello.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    So, if you already have a .pro file (project file) you just need to copy the source from windows into linux. Then remove any .o moc_* ui_* and makefile. Then run qmake where the .pro is (this will generate new moc_ and ui_ files) then run make.

    If you don't have a pro file, you can use this as template:
    helloWorld.pro
    Qt Code:
    1. QT += core gui
    2. TARGET = HelloWorld
    3. TEMPLATE = app
    4. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: Porting HelloWorld Qt Application from WINDOWS to LINUX

    Do you want to cross-compile, i.e. build a Linux executable in a Windows environment, or just build it on a Linux box? The latter option is trivial. The former option, well, I've never heard of anyone developing for Linux on a Windows machine.

  4. #4
    Join Date
    Feb 2011
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Porting HelloWorld Qt Application from WINDOWS to LINUX

    Thanks qlands & Chris.

    Chris,
    Yes, my goal is to create an application which will be running primarily on Windows and for few customers on Linux platform. Since I am not familiar with cross-compiling, I raised this question. I don't want to compile my code again in a Linux machine.

    I heard that using Qt, we can cross compile to Linux platform from Windows environment. Could you please help me to learn Qt Cross-Compilation.

    Regards,
    Sankar.
    Last edited by sankar; 20th September 2011 at 07:46.

  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: Porting HelloWorld Qt Application from WINDOWS to LINUX

    If you want to cross-compile, you need a cross-compiler. You could probably follow this description: http://metamod-p.sourceforge.net/cro...for.linux.html. However I think it is much simpler to either run a livecd Linux distribution or install a Linux distribution on VirtualBox and build from within there. Otherwise you will have to first cross-compile Qt and possibly other libraries your application requires.
    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.


  6. #6
    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: Porting HelloWorld Qt Application from WINDOWS to LINUX

    Quote Originally Posted by sankar View Post
    Yes, my goal is to create an application which will be running primarily on Windows and for few customers on Linux platform.
    Doesn't require cross-compiling.
    Since I am not familiar with cross-compiling, I raised this question. I don't want to compile my code again in a Linux machine.
    Please tell me that there is reason for this other than you think it is easier. Cross-compiling on one platform for another is always more work than building natively. You have to establish Win32 tool chains and compilers that target Linux, build any Linux libraries that Qt depends on, build Qt, build any other libraries your app requires, and then hack a Qt prf file to use these tools. (Some of that might be available in Cygwin: see the very old http://metamod-p.sourceforge.net/cro...for.linux.html) You're going to have to have Linux machine(s) (virtual machine is fine) to test on anyway, so why not build there.
    I heard that using Qt, we can cross compile to Linux platform from Windows environment. Could you please help me to learn Qt Cross-Compilation.
    Where did you hear that? Qt makes it easy to take the same source and build it in different environments. There are tools to build on Linux and Windows targeting the mobile platforms. There are reasonably straightforward ways to cross-compile on Linux for embedded Linux. Getting a compiler suite and tool chain on Linux to target Windows is also reasonably easy thanks to MingW (e.g. http://silmor.de/29). I have not seen instructions to go the other way in recent times.

Similar Threads

  1. Porting Qt application from linux to Windows
    By ankit17.ag in forum Qt Programming
    Replies: 5
    Last Post: 12th February 2009, 21:18
  2. Linux to Windows Porting
    By qtprogrammer12345 in forum Qt Tools
    Replies: 1
    Last Post: 23rd May 2008, 07:28
  3. Porting Qt Application from Windows to Linux
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 12th July 2007, 13:30
  4. Porting Qt application on windows from linux
    By safknw in forum Qt Programming
    Replies: 13
    Last Post: 22nd May 2006, 13:11
  5. Porting Qt3 linux app to windows qt4
    By Philip_Anselmo in forum Qt Programming
    Replies: 7
    Last Post: 15th May 2006, 18:44

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.