简体   繁体   English

Qt是如何工作的(确切地说)?

[英]How does Qt work (exactly)?

When you write an application using Qt, can it just be run right away in different operating systems? 使用Qt编写应用程序时,是否可以立即在不同的操作系统中运行? And (correct me if I'm wrong) you don't need to have Qt already installed in all of the different platforms where you want to execute your application? 并且(如果我错了,请纠正我)您不需要在要执行应用程序的所有不同平台上安装Qt吗?

How exactly does this work? 这究竟是如何工作的? Does Qt compile to the desired platform, or does it bundle some "dlls" (libs), or how does it do it? Qt是否编译到所需的平台,或者是否捆绑了一些“dll”(libs),或者它是如何做到的? Is it different from programming a Java application, that runs cross-platform. 它是否与编写跨平台运行的Java应用程序不同。

If you use Python to write a Qt application with Python bindings, does your end user need to have Python installed? 如果您使用Python编写带有Python绑定的Qt应用程序,您的最终用户是否需要安装Python?

Qt (ideally) provides source compatibility, not binary compatibility. Qt(理想情况下)提供源兼容性,而不是二进制兼容性。 You still have to compile the application separately for each platform, and use the appropriate dynamic Qt libraries (which also need to be compiled separately, and have some platform-specific code). 您仍然需要为每个平台单独编译应用程序,并使用适当的动态Qt库(它们也需要单独编译,并具有一些特定于平台的代码)。

For your final question, the user would need Python, the Qt libraries, and the binding library (eg pyqt), but there are various ways to bundle these. 对于您的最后一个问题,用户需要Python,Qt库和绑定库(例如pyqt),但有各种方法可以捆绑这些。

PyQT [and its open source cousin PySide] are a great cross-platform QT binding for python, but it is not a magic solution for shipping your application for all platforms without doing any packaging/installer maintenance. PyQT [和它的开源堂兄PySide]是一个很好的跨平台QT绑定python,但它不是一个神奇的解决方案,无需进行任何打包/安装程序维护,为所有平台运送您的应用程序。 I think maybe you might be expecting some magic. 我想也许你可能会期待一些魔力。

QT is a cross-platform library written in C++. QT是一个用C ++编写的跨平台库。 That means, you can write your C++ or Python (or other language with bindings) code once, and create a "window" (a form, a dialog box, something on the screen) and populate it with controls (buttons, and all that) and not have to deal with the platform differences in how buttons are made in Windows, Linux, and on Mac OS X. 这意味着,您可以编写一次C ++或Python(或带有绑定的其他语言)代码,并创建一个“窗口”(窗体,对话框,屏幕上的某些内容)并使用控件(按钮等等)填充它并且不必处理在Windows,Linux和Mac OS X上如何制作按钮的平台差异。

Because it is a library, it can be packaged in multiple ways. 因为它是一个库,所以它可以以多种方式打包。 It can be "statically linked" (built into your executable/binary/app) or "dynamically linked" (known as a DLL in windows, a shared library or on unix/linux or as a framework, in mac os x). 它可以是“静态链接”(内置于您的可执行文件/二进制/应用程序中)或“动态链接”(在Windows中称为DLL,共享库或unix / linux上的DLL或作为框架,在mac os x中)。 It is not always "installed" on a computer, unless it is a shared library. 它并不总是“安装”在计算机上,除非它是共享库。

Even when it is "installed" onto a computer, multiple versions might exist on that computer, and so it is not proper to think of it as being an extension to your computer, but rather an extension to an application (a program) on your computer. 即使它“安装”到计算机上,该计算机上可能存在多个版本,因此将其视为计算机的扩展是不恰当的,而是对您的计算机上的应用程序(程序)的扩展电脑。

If you use Python bindings for QT, then your installation package for your application needs to include the QT binding's binary files (python extensions), the basic Python runtime environment including the Python executable and basic libraries, and your program's source code. 如果您对QT使用Python绑定,那么您的应用程序的安装包需要包含QT绑定的二进制文件(python扩展),基本的Python运行时环境,包括Python可执行文件和基本库,以及程序的源代码。 It is possible to package most of this up into a single "bundle". 可以将大部分内容打包成一个“捆绑”。 On Mac OS X, for instance, all this can easily be put into a an ".app" bundle, and on Windows, and Linux, I believe there are packaging and installation tools that can help you do this easily. 例如,在Mac OS X上,所有这些都可以轻松地放入“.app”软件包中,在Windows和Linux上,我相信有一些打包和安装工具可以帮助您轻松完成。

Even though you will only need to write the user interface code for your application once, you will not magically get the ability to ship an application on all three primary platforms at once, without doing at least the building of the installer or packaging, separately for each platform. 即使您只需要为应用程序编写一次用户界面代码,您也不会神奇地获得同时在所有三个主平台上发布应用程序的能力,而无需至少进行安装程序或打包的构建。每个平台。 Users expect to download a setup/install package for Windows or Mac OS X, and perhaps for Unix/Linux it depends further on which distribution you install. 用户希望下载适用于Windows或Mac OS X的安装/安装包,也许对于Unix / Linux,它还取决于您安装的分发版。

Update thanks to AdamW for this nokia link providing deployment information 感谢AdamW为此诺基亚链接提供部署信息

The problem is your definition of "installed". 问题是你对“已安装”的定义。 For Qt to work, the executable just has to have access to the proper libraries. 要让Qt工作,可执行文件必须能够访问正确的库。

Of course that for each platform a different executable and libraries have to be produced (see Qt docs ). 当然,对于每个平台,必须生成不同的可执行文件和库(请参阅Qt文档 )。

About Python, if you are to run a Python executable you have to have it installed (in a more traditional kind of way). 关于Python,如果要运行Python可执行文件,则必须安装它(以更传统的方式)。 Unless you are running with py2exe in Windows, for instance. 例如,除非您在Windows中使用py2exe运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM