Install Qt Platform Plugin Windows 10

Install Qt Platform Plugin Windows 10

Plugins are a great way to extend the functionality of QGIS. You can write plugins using Python that can range from adding a simple button to sohpisticated toolkits. This tutorial will outline the process involved in setting up your development environment, designing the user interface for a plugin and writing code to interact with QGIS. Please review the Getting Started With Python Programming (QGIS3) tutorial to get familiar with the basics.

Note

If you are building a new plugin, I strongly recommend building a Processing Plugin instead of the GUI plugin described in this tutorial. See Building a Processing Plugin (QGIS3) for details.

Reinstall Qt Platform Plugin Windows

Pro tips and tricks on how to install Qt Open Source on Windows 10Also available on udemy(0:00)Step 1. Free qt platform plugin windows download software at UpdateStar - Osqoop is a software oscilloscope. It features anarbitrary number of channels and long acquisitiondurations. Signal processing and externalperipherals control are possible through a pluginarchitecture.

Overview of the Task¶

We will develop a simple plugin called SaveAttributes that will allow users to pick a vector layer and write its attributes to a CSV file.

Get the Tools¶

Qt Creator¶

Qt is a software development framework that is used to develop applications that run on Windows, Mac, Linux as well as various mobile operating systems. QGIS itself is written using the Qt framework. For plugin development, we will use an application called Qt Creator to design the interface for our plugin.

Download and install the Qt Creator installer from Qt Offline Installers. Make sure you select Qt Creator on the download page. Note that you will have to create a free Qt account to install the package.

Note

OSGeo4w installer for QGIS on Windows include a copy of Qt Designer program which is a lightweight version of Qt Creator and perfectly suitable for building plugins. You may skip downloading Qt Creator and use it instead from C:OSGeo4W64binqgis-designer.

Python Bindings for Qt¶

Since we are developing the plugin in Python, we need to install the pythonbindings for Qt. The method for installing these will depend on the platformyou are using. For building plugins we need the pyrcc5 command-line tool.

What is the qt platform plugin windows

Windows

Relevant pyhon bindings are included in the QGIS install on Windows. But to use them from the plugin folder, we need to indicate the path to the QGIS install.

Create a Windows Batch file (.bat extension) with the following content and save it on your computer as compile.bat. We will later copy this file to the plugin folder. If you installed QGIS at a different path, replace the C:OSGeo4W64bin with your path.

Mac

Install the Homebrew package manager. Install PyQt package by running the following command:

Linux
Platform

Depending on your distribution, find and install the python-qt5 package. On Ubuntu and Debian-based distributions, you can run the following command:

What Is Qt Platform Plugin Windows 10

Note

You may find that QGIS has already installed this package.

A Text Editor or a Python IDE¶

Any kind of software development requires a good text editor. If you already have a favorite text editor or an IDE (Integrated Development Environment), you may use it for this tutorial. Otherwise, each platform offers a wide variety of free or paid options for text editors. Choose the one that fits your needs.

This tutorial uses Notepad++ editor on Windows.

Windows

Notepad++ is a good free editor for windows.Download and install the Notepad++ editor.

Note

If you are using Notepad++, makes sure to go to Settings ‣ Preferences ‣ Tab Settings and enable Replace by space. Python is very sensitive about whitespace and this setting will ensure tabs and spaces are treated properly.

Plugin Builder plugin¶

There is a helpful QGIS plugin named PluginBuilder which creates all the necessary files and the boilerplate code for a plugin. Find and install the PluginBuilder plugin. See Using Plugins for more details on how to install plugins.

Plugins Reloader plugin¶

This is another helper plugin which allows iterative development of plugins. Using this plugin, you can change your plugin code and have it reflected in QGIS without having to restart QGIS every time. Find and install the PluginReloader plugin. See Using Plugins for more details on how to install plugins.

Note

Plugin Reloader is an experimental plugin. Make sure you have checked Show also experimental plugins in Plugin Manager settings if you cannot find it.

Procedure¶

  1. Open QGIS. Go to Plugins ‣ Plugin Builder ‣ Plugin Builder.

  1. You will see the QGIS Plugin Builder dialog with a form. You can fill the form with details relating to our plugin. The Class name will be the name of the Python Class containing the logic of the plugin. This will also be the name of the folder containing all the plugin files. Enter SaveAttributes as the class name. The Plugin name is the name under which your plugin will appear in the Plugin Manager. Enter the name as SaveAttributes. Add a description in the Description field. The Module name will be the name of the main python file for the plugin. Enter it as save_attributes. Leave the version numbers as they are and enter your name and email address in the appropriate fields. Click Next.

  1. Enter a brief description of the plugin for the About dialog and click Next.

  1. Select the Toolbuttonwithdialog from the Template selector`. The Text for menu item value will be how the users will find your plugin in QGIS menu. Enter it as SaveAttributesasCSV. The Menu field will decide where your plugin item is added in QGIS. Since our plugin is for vector data, select Vector. Click Next.

  1. Plugin builder will prompt you for the type of files to generate. Keep the default selection and click Next.

  1. As we do not intend to publish the plugin, you may leave the Bug tracker, Repository and Home page values to default. Check the Flag the plugin as experimental box at the bottom and click Next.

  1. You will be prompted to choose a directory for your plugin. For now, save it to a directory you can locate easily on your computer and click Generate.

  1. Next, press the generate button. You will see a confirmation dialog once your plugin template is created.

Note

You may get a prompt saying that pyrcc5 is not found in the path. You can ignore this message.

  1. Before we can use the newly created plugin, we need to compile the resources.qrc file that was created by Plugin Builder. This file is part of the Qt Resource System which references all binary files used in the plugin. For this plugin, it will only have the plugin icon. Compiling this file generates application code that can be used in the plugin independent which platform the plugin is being run. Follow the platform specific instruction for this step.

Windows

You can now copy the compile.bat file (created during the Python Bindings for Qt section at the start) to the plugin folder. Once copied, double-click the file to run it. If the run was successful, you will see a new file called resources.py in the folder.

Note

If this step fails, you can launch cmd.exe and browse to the plugin folder using cd command. Run the Batch file by running compile.bat to see the error.

Mac and Linux

You will need to install pb_tool first. Open a Terminal and install it via pip.

Open a Terminal and go to the plugin directory and type pb_toolcompile. This will run the pyrcc5 command that we had installed as part Python Bindings for Qt section.

  1. Plugins in QGIS are stored in a special folder. We must copy our plugin directory to that folder before it can be used. In QGIS, locate your current profile folder by going to Settings ‣ User Profiles ‣ Open Active Profile Folder.

  1. In the profile folder, copy the plugin folder to python ‣ plugins subfolder.

  1. Now we are ready to have a first look at the brand new plugin we created. Close QGIS and launch it again. Go to Plugins ‣ Manage and Install plugins and enable the SaveAttributes plugin in the Installed tab.

  1. You will notice that there is a new icon in the plugin toolbar and a new menu entry under Vector ‣ Save Attributes ‣ Save Attributes as CSV`. Select it to launch the plugin dialog.

  1. You will notice a new blank dialog named Save Attributes. Close this dialog.

  1. We will now design our dialog box and add some user interface elements to it. Open the QtCreator program and go to File ‣ Open File or Project.

  1. Browse to the plugin directory and select the save_attributes_dialog_base.ui file. Click Open.

Note

Windows hides the AppData folder so you may not see it in the file selector dialog. You can enter AppData in the File name prompt from its parent directory to open it.

  1. You will see the blank dialog from the plugin. You can drag-and-drop elements from the left-hand panel on the dialog. We will add a Combo Box type of Input Widgets. Drag it to the plugin dialog.

  1. Resize the combo box and adjust its size. Now drag a Label type Display Widget on the dialog.

  1. Click on the label text and enter Selectalayer.

Install Qt Platform Plugin Windows 10

  1. Save this file by going to File ‣ Save save_attributes_dialog_base.ui. Note the name of the combo box object is comboBox. To interact with this object using python code, we will have to refer to it by this name.

  1. Let’s reload our plugin so we can see the changes in the dialog window. Go to Plugin ‣ Plugin Reloader ‣ Choose a plugin to be reloaded. Select SaveAttributes in the Configure Plugin reloader dialog.

  1. Click the Reload plugin button to load the latest version of the plugin. Click the Save Attributes as CSV button to open the newly designed dialog box.

Qt Platform Plugin Windows Vista

  1. Let’s add some logic to the plugin that will populate the combo box with the layers loaded in QGIS. Go to the plugin directory and load the file save_attributes.py in a text editor. First, insert at the top of the file with the other imports:

    Then scroll down to the end and find the run(self) method. This method will be called when you click the toolbar button or select the plugin menu item. Add the following code at the beginning of the method. This code gets the layers loaded in QGIS and adds it to the comboBox object from the plugin dialog.

  1. Back in the main QGIS window, reload the plugin by clicking on the Reload plugin button. To test this new functionality, we must load some layers in QGIS. After you have loaded some layers, launch the plugin by going to Vector ‣ Save Attributes ‣ Save Attributes as CSV. You will see that our combo box is now populated with the layer names that are loaded in QGIS.

  1. Let’s add the remaining user interface elements. Switch back to Qt Creator and load the save_attributes_dialog_base.ui file. Add a LabelDisplay Widget and change the text to Selectoutputfile. Add a LineEdit type Input Widget that will show the output file path that the user has chosen. Next, add a PushButton type Button and change the button label to .... Note the object names of the widgets that we will have to use to interact with them. Save the file.

  1. We will now add python code to open a file browser when the user clicks the ... push button and show the select path in the line edit widget. Open the save_attributes.py file in a text editor. Add QFileDialog to QtWidgets list of imports at the top of the file.

  1. Add a new method called select_output_file with the following code. This code will open a file browser and populate the line edit widget with the path of the file that the user chose. Note, how getSaveFileName returns a tuple with the filename and the filter used.

  1. Now we need to add code so that when the button is clicked, select_output_file method is called. Scroll down to the run method and add the following line in the block where the dialog is initialized. This code will connect the select_output_file method to the clicked signal of the push button widget.

  1. Back in QGIS, reload the plugin and run it. If all went fine, you will be able to click the ... button and select an output text file from your disk.

  1. When you click OK on the plugin dialog, nothing happens. That is because we have not added the logic to pull attribute information from the layer and write it to the text file. We now have all the pieces in place to do just that. Find the place in the run method where it says pass. Replace it with the code below. The explanation for this code can be found in Getting Started With Python Programming (QGIS3).

  2. We have one last thing to add. When the operation finishes successfully, we should indicate the same to the user. The preferred way to give notifications to the user in QGIS is via the self.iface.messageBar().pushMessage() method. Add Qgis to qgis.core list of imports at the top of the file and add the code below at the end of the run method.

  1. Now our plugin is ready. Reload the plugin and try it out. You will find that the output text file you chose will have the attributes from the vector layer.

  1. You can zip the plugin directory and share it with your users. They can unzip the contents to their plugin directory and try out your plugin. If this was a real plugin, you would upload it to the QGIS Plugin Repository so that all QGIS users will be able to find and download your plugin.

Note

This plugin is for demonstration purpose only. Do not publish this plugin orupload it to the QGIS plugin repository.

How To Install Qt Platform Plugin Windows 10

Below is the full save_attributes.py file as a reference.