views:

2589

answers:

6

hello,

Is it possible to create an executable for Linux and windows using the same QT code in Linux with Eclipse integration or is it necessary to install QT Creator in my Linux machine?

Waiting for reply

Thanks in advance

vincat.

A: 

Of course, it is possible to install Qt Creator in Linux. The same Qt code can be used to compile in Linux/Win32/Mac. However, you should be using platform specific code only within:

#ifdef Q_OS_WIN32
    qDebug() << "Executable files end in .exe";
#endif

There are other defines for other operating systems. If you do so, you are safe and you can bet it is cross-platform code. :-)

Please refer http://www.qtsoftware.com/downloads and download the Qt SDK for Linux/X11. It contains Qt Creator, Assistant, Designer, et cetera.

Alan Haggai Alavi
Actually i need to create Windows executable in Linux using QT, and my requirement says that i need to install just the Windows QT binary and run the executable which i create in Linux. So please tel me can i create both Linux and Windows executable using QT Eclipse integration in Linux.I'm able to get Linux executable for my program, but how to get windows executable for the same in Linux?
This is a link on how to cross-compile for Windows from within Linux - http://silmor.de/29
Alan Haggai Alavi
A: 

For Eclipse, there's an official plugin.

Qt Eclipse Integration for C++

The Eclipse plugin can be used to create programs using any Qt version since 4.1.0.

brunoqc
+1  A: 

Some time ago I was trying to do this, and I found resources about cross-compiling here: http://silmor.de/29. Finally I compiled win32 version under Windows, because of lack of time, but it should be possible.

samuil
A: 

If you want to build a windows binary on linux you need to cross-compile. This means you need to have a windows cross-compiler installed plus the libraries you are linking with built with the cross compiler. For a basic Qt program this means you need at least a cross-compiled Qt.

Cross-compiling has nothing to do with Eclipse or Qt Creator. I don't think both support cross compiling out of the box but I guess you could make them to do so.

bluebrother
Actually i need to create Windows executable in Linux using QT, and my requirement says that i need to install just the Windows QT binary and run the executable which i create in Linux.So please tel me can i create both Linux and Windows executable using QT Eclipse integration in Linux.
I'm able to get Linux executable for my program, but how to get windows executable for the same in Linux?
Sorry, but your question is unclear to me. If you want to cross-compile a Windows binary on Linux you need to cross-compile Qt first, and you need to do that yourself. I haven't seen *any* pre-packaged cross-compiled Qt for any OS.Qt Eclipse integration doesn't create any binaries at all. It runs the compiler, and to build Windows binaries on Linux you need a cross-compiler installed
bluebrother
No Vincat, your linux executable will not run in Windows. You need to do what bluebrother suggested: you need to cross-compile it for Windows. That means you install on your linux machine a cross-compiling package that will compile your code for Windows and link against the Windows libraries. Then you can use THAT executable on Windows. Look into the MinGW compiler, I know it compiles Qt on Windows and has cross-compilers available for linux.
Bob Somers
A: 

executable in windows does not work in linux and vice versa. you can do this:

#ifdef Q_WS_X11
QString *OS=new QString("Linux");
std::cout << OS->toStdString() << std::endl;
#endif
#ifdef Q_WS_WIN
QString *OS=new QString("Windows");
std::cout << OS->toStdString() << std::endl;
#endif
#ifdef Q_WS_MACX
QString *OS=new QString("Mac");
std::cout << OS->toStdString() << std::endl;    
#endif
George Gorelishvili
A: 

Been lookiing at this myself and found this article http://www.ce3c.be/152-cross-compiling-qt-c-for-windows-on-linux/

Robert Smit