PDA

View Full Version : Porting HelloWorld Qt Application from WINDOWS to LINUX



sankar
20th September 2011, 06:27
Hello,

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

Regards,
Sankar.

qlands
20th September 2011, 08:18
Hi,

Im guessing the hello world example is:

main.cpp


include <qapplication.h>
include <qpushbutton.h>

int main( int argc, char **argv )
{
QApplication a( argc, argv );

QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );

a.setMainWidget( &hello );
hello.show();
return a.exec();
}


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 += core gui
TARGET = HelloWorld
TEMPLATE = app
SOURCES += main.cpp

ChrisW67
20th September 2011, 08:19
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.

sankar
20th September 2011, 08:33
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.

wysota
20th September 2011, 09:18
If you want to cross-compile, you need a cross-compiler. You could probably follow this description: http://metamod-p.sourceforge.net/cross-compiling.on.windows.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.

ChrisW67
20th September 2011, 09:29
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/cross-compiling.on.windows.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.