My recent blog post covered how to set up Qt and Qt Creator on a Windows 10 system. In this post I'll look at how to configure a Linux system for Qt desktop development.
$./qt-unified-linux-x64-2.0.3-1-online.run For the global install you can run it as root using the sudo command, e.g. $ sudo./qt-unified-linux-x64-2.0.3-1-online.run The installer should now launch. The steps will be the same as on Windows. The previous blog post provided screen shots and described each step in the installer process in detail. After running qmake, a makefile is generated that can be used to build the Qt plug-in. To build the Qt plug-ins provided with the Maya Developer Kit, follow these steps: Use the following Qt archives from the Maya installation, and extract them in place.
Since the set up process on Linux is almost identical to that on Windows, rather than repeat the information I refer you to that blog. (Keep it handy, you'll need it later.) In this post, I'll cover the differences.
Assumptions and Prerequisites
For this example I will assume you want to install Qt 5.6.0 or 5.7.0 on a recent release of Ubuntu Desktop Linux. The procedure will be similar with other Linux distributions. As in the blog for Windows, we will use Qt's online installer.
It should be noted that many Linux distributions already have Qt and Qt Creator available as standard distribution packages. This is often the easiest way to set up a Qt development environment. On Ubuntu Linux, for example, you can install Qt Creator using the command:
A downside of this approach is that the versions of Qt and Creator packaged for your Linux distribution may not be the latest versions, and you are typically only offered one particular Qt version. Using the Qt online installer as I describe here will allow you to install the latest Qt release or one or more older releases, as well as install optional modules that may not be available as packages for your Linux distribution.
The Qt installer for Linux does not include a C++ compiler. You will need to separately install the GNU gcc compiler, make program, and other packages for software development. In addition, building graphical Qt applications requires OpenGL libraries and headers installed. On Ubuntu and other Debian-based Linux systems you can get OpenGL and the minimal set of development tools by installing the packages libgl1-mesa-dev and build-essential, i.e. by running this command:
This is the bare minimum needed for software development. You will typically also want to install the gdb debugger (packaged as gdb on Ubuntu) and possibly some optional tools like git, clang, etc. Qt Creator will make use of these if present and you can install them any time after installing Qt Creator, if desired.
Installation Steps
The first step is to download the online installer. You can directly download the latest installer from http://download.qt.io/official_releases/online_installers/
You need to select either the 32-bit or 64-bit installer, depending on the architecture of your system. The file qt-unified-linux-x86-online.run is the 32-bit installer and qt-unified-linux-x64-online.run is the 64-bit version. If you are unsure what architecture your system is running, you can run the Linux command arch and examine the output. An output of 'i686' indicates 32-bit and 'x86_64' is 64-bit on Intel-compatible systems.
Select and download the appropriate installer. Your web browser probably won't let you directly run it until you make the file executable. You can do that by opening a terminal window, navigating to the downloads directory, and using the chmod command. Here is an example:
You are now ready to run the installer. You have two options. If you run it as a normal user, it will be installed in the current user's home directory, making the install suitable for use only by the user who installed it. If you run the installer as root, it will be installed globally and be available to all users on the machine.
For the per user install, the default installation will be a subdirectory called Qt in the current working directory. For the global install, the default location is /opt/Qt.
Determine whether you want to install per user or global and then run the installer. For a per user install, just run it as the current user, e.g.
For the global install you can run it as root using the sudo command, e.g.
The installer should now launch. The steps will be the same as on Windows. The previous blog post provided screen shots and described each step in the installer process in detail.
Once done, you can launch Qt Creator.
You should check that it correctly set up at least one auto-detected kit, compiler, Qt version, and debugger (if present):
As I suggested in the other blog, this would be a good time to create some sample projects to test your installation. Use the New Project Wizard and confirm that you can create the project, build it and run the application. Testing both widget and QML-based projects is recommended.
You are now ready for Qt software development!
If you want to update, add or remove any components, you can run the maintenance tool, which can be found under the install directory as MaintenanceTool.
Summary
As on Windows, it's easy to install a Qt development environment on desktop Linux.
We didn't cover the Mac desktop platform, but it is much the same as Linux. However, you need to install Apple's XCode IDE to get the C++ compiler and other necessary development tools.
For the most flexibility, you may want to build Qt yourself from source code. This offers a number of advantages, including ability to run Alpha and Beta versions of Qt before they are officially released. I'll cover this in a future post.
fbs is a cross-platform PyQt5 packaging system which supports building desktop applications for Windows, Mac and Linux (Ubuntu, Fedora and Arch). Built on top of PyInstaller it wraps some of the rough edges and defines a standard project structure which allows the build process to be entirely automated. The included resource API is particularly useful, simplifying the handling of external data files, images or third-party libraries — a common pain point when bundling apps.
This tutorial will take you through the steps of creating PyQt5 applications using fbs from scratch, and for converting existing projects over to the system. If you’re targeting multiple platforms with your app, it's definitely worth a look.
If you're impatient, you can grab the Moonsweeper installers directly for Windows, MacOS or Linux (Ubuntu).
fbs is licensed under the GPL. This means you can use the fbs system for free in packages distributed with the GPL. For commercial (or other non-GPL) packages you must buy a commercial license. See the fbs licensing page for up-to-date information.
fbs is built on top of PyInstaller. You can also use PyInstaller directly to package applications, see our Packaging PyQt5 & PySide2 applications for Windows, with PyInstaller tutorial.
Install requirements
fbs works out of the box with both PyQt
PyQt5
and Qt for Python PySide2
. The only other requirement is PyInstaller
which handles the packaging itself. You can install these in a virtual environment (or your applications virtual environment) to keep your environment clean. fbs only supports Python versions 3.5 and 3.6 Typing applications for mac.
Once created, activate the virtual environment by running from the command line --
bash
Finally, install the required libraries. For PyQt5 you would use --
![Catalina Catalina](/uploads/1/3/4/1/134186567/603601188.jpg)
Can Qt App Built For Linux Run On Mac Catalina
Or for Qt for Python (PySide2) --
python
fbs installs a command line tool
fbs
into your path which provides access to all fbs management commands. To see the complete list of commands available run fbs
.Now you're ready to start packaging applications with fbs.
Starting an app
If you’re starting a PyQt5 application from scratch, you can use the
fbs startproject
management command to create a complete, working and packageable application stub in the current folder. This has the benefit of allowing you to test (and continue to test) the packageability of your application as you develop it, rather than leaving it to the end. App tv online mac.bash
The command walks you through a few questions, allowing you to fill in details of your application. These values will be written into your app source and configuration. The bare-bones app will be created under the
src/
folder in the current directory. If you already have your own working PyQt5 app you will need to either a) use the generated app as a guideline for converting yours to the same structure, or b) create a new app using `startproject` and migrate the code over.
Running your new project
You can run this new application using the following fbs command in the same folder you ran
startproject
from. bash
Roller coaster tycoon 1 mac free download full version. If everything is working this should show you a small empty window with your apps' title — exciting eh?
Hello World App on Windows
Hello World App on Mac
Lock keyboard mac app. Hello World App on Linux
The application structure
The
startproject
command generates the required folder structure for a fbs PyQt5 application. This includes a src/build
which contains the build settings for your package, main/icons
which contains the application icons, and src/python
for the source.Your bare-bones PyQt5 application is generated in
src/main/python/main.py
and is a complete working example you can use to base your own code on. https://yellowrecord651.weebly.com/photshop-cs2-keygen.html.python
If you’ve built PyQt5 applications before you’ll notice that building an application with fbs introduces a new concept — the
ApplicationContext
.The ApplicationContext
When building PyQt5 applications there are typically a number of components or resources that are used throughout your app. These are commonly stored in the
QMainWindow
or as global vars which can get a bit messy as your application grows. The ApplicationContext
provides a central location for initialising and storing these components, as well as providing access to some core fbs features.The
ApplicationContext
object also creates and holds a reference to a global QApplication
object — available under ApplicationContext.app
. Every Qt application must have one (and only one) QApplication
to hold the event loop and core settings. Without fbs you would usually define this at the base of your script, and call .exec()
to start the event loop. Without fbs this would look something like this —
The equivalent with fbs would be --
python
If you want to create your own custom `QApplication` initialisation you can overwrite the `.app` property on your `ApplicationContext` subclass using `cached_property` (see below).
This basic example is clear to follow. However, once you start adding custom styles and translations to your application the initialisation can grow quite a bit. To keep things nicely structured fbs recommends creating a
.run
method on your ApplicationContext
. This method should handle the setup of your application, such as creating and showing a window, finally starting up the event loop on the
.app
object. This final step is performed by calling self.app.exec_()
at the end of the method.As your initialisation gets more complicated you can break out subsections into separate methods for clarity, for example --
python
Can Qt App Built For Linux Run On Mac Os
On execution the `.run()` method will be called and your event loop started. Execution continues in this event loop until the application is exited, at which point your `.run()` method will return (with the appropriate exit code).
Building a real application
The bare-bones application doesn’t do very much, so below we’ll look at something more complete — the Moonsweeper application from my 15 minute apps. The updated source code is available to download below.
Only the changes required to convert Moonsweeper over to fbs are covered here. If you want to see how_ Moonsweeper_ itself works, see the original App article. The custom application icons were created using icon art by Freepik.
The project follows the same basic structure as for the stub application we created above.
The
src/build/settings/base.json
stores the basic details about the application, including the entry point to run the app with fbs run
or once packaged.json
The script entry point is at the base of
src/main/python/main.py
. This creates the AppContext
object and calls the .run()
method to start up the app.The
ApplicationContext
defines a .run()
method to handle initialisation. In this case that consists of creating and showing the main window, then starting up the event loop. python
The cached_property
decorator
The
.run()
method accesses self.main_window
. You’ll notice that this method is wrapped in an fbs@cached_property
decorator. This decorator turns the method into a property (like the Python @property
https://sgsttl.weebly.com/blog/nest-app-fur-mac. decorator) and caches the return value.The first time the property is accessed the method is executed and the return value cached. On subsequent calls, the cached value is returned directly without executing anything. This also has the side-effect of postponing creation of these objects until they are needed.
You can use
@cached_property
to define each application component (a window, a toolbar, a database connection or other resources). However, you don’t have to use the @cached_property
— you could alternatively declare all properties in your ApplicationContext.__init__
block as shown below. Accessing resources with .get_resource
Applications usually require additional data files beyond the source code — for example files icons, images, styles (Qt’s
.qss
files) or documentation. You may also want to bundle platform-specific libraries or binaries. To simplify this fbs defines a folder structure and access method which work seamlessly across development and distributed versions.The top level folder
resources/
should contain a folder base
plus any combination of the other folders shown below. The base
folder contains files common to all platforms, while the platform-specific folders can be used for any files specific to a given OS.bash
Getting files into the right place to load from a distributed app across all platforms is usually one of the faffiest bits of distributing PyQt applications. It’s really handy that fbs handles this for you.
To simplify the loading of resources from your
resources/
folder in your applications fbs provides the ApplicationContext.get_resource()
method. This method takes the name of a file which can be found somewhere in the resources/
folder and returns the absolute path to that file. You can use this returned absolute path to open the file as normal.In our Moonsweeper application above, we have a bomb image file available at
src/main/resources/base/images/bug.jpg
. By calling ctx.get_resource('images/bug.png')
we get the absolute path to that image file on the filesystem, allowing us to open the file within our app. If the file does not exist `FileNotFoundError` will be raised instead.
The handy thing about this method is that it transparently handles the platform folders under
src/main/resources
giving OS-specific files precedence. For example, if the same file was also present under src/main/resources/mac/images/bug.jpg
and we called ctx.get_resource('images/bug.jpg')
we would get the Mac version of the file.Additionally
get_resource
works both when running from source and when running a frozen or installed version of your application. If your resources/
load correctly locally you can be confident they will load correctly in your distributed applications.Using the ApplicationContext
from app
As shown above, our
ApplicationContext
object has cached properties to load and return the resources. To allow us to access these from our QMainWindow
we can pass the context in and store a reference to it in our window __init__
. python
Now that we have access to the context via
self.ctx
we can use it this in any place we want to reference these external resources.The first time we access
self.ctx.img_bomb
the file will be loaded, the QImage
created and returned. On subsequent calls, we’ll get the image from the cache.python
Those are all the changes needed to get the Moonsweeper app packageable with fbs. If you open up the source folder you should be able to start it up as before.
If that’s working, you’re ready to move onto freezing and building in the installer.
Freezing the app
Freezing is the process of turning a Python application into a standalone executable that can run on another user’s computer. Use the following command to turn the app's source code into a standalone executable:
python
The resulting executable depends on the platform you freeze on — the executable will only work on the OS you built it on (e.g. an executable built on Windows will run on another Windows computer, but not on a Mac).
- Windows will create an
.exe
executable in the foldertarget/<AppName>
- MacOS X will create an
.app
application bundle intarget/<AppName>.app
- Linux will create an executable in the folder
target/<AppName>
On Windows you may need to install the Windows 10 SDK, although fbs will prompt you if this is the case.
Creating the Installer
While you can share the executable files with users, desktop applications are normally distributed with installers which handle the process of putting the executable (and any other files) in the correct place. See the following sections for platform-specific notes before creating
You must freeze your app first then create the installer.
Windows installer
The Windows installer allows your users to pick the installation directory for the executable and adds your app to the user’s Start Menu. The app is also added to installed programs, allowing it to be uninstalled by your users.
https://sgsttl.weebly.com/blog/mac-battery-check-app. Before you create installers on Windows you will need to install NSIS and ensure its installation directory is in your
PATH
. You can then build an installer using --The Windows installer will be created at
target/<AppName>Setup.exe
.Moonsweeper Windows NSIS installer
Mac installer
There are no additional steps to create a MacOS installer. Just run the fbs command --
bash
On Mac the command will generate a disk image at
target/<AppName>.dmg
. This disk image will contain the app bundle and a shortcut to the Applications folder. When your users open it they can drag the app to the Applications folder to install it.Moonsweeper Mac Disk Image
Linux installer
To build installers on Linux you need to install the Ruby tool Effing package management! — use the installation guide to get it set up. Once that is in place you can use the standard command to create the Linux package file.
The resulting package will be created under the
target/
folder. Depending on your platform the package file will be named <AppName>.deb
, <AppName>.pkg.tar.xz
or <AppName>.rpm
. Your users can install this file with their package manager.