Creating executable for Windows using Qt on Linux

冷暖自知 提交于 2019-11-30 05:15:11

问题


Is it possible to create an executable on Linux for both Linux and Windows using the same Qt code with Eclipse? Or is it necessary to install Qt Creator on my Linux machine?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.




回答5:


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


来源:https://stackoverflow.com/questions/963611/creating-executable-for-windows-using-qt-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!