This document demonstrates how to use the QT GUI features in GNU Radio. There is one main QT interface defined that comes as either a complex sink or floating point sink, they are called:
As this shows, the sinks are located in the module gnuradio.qtgui and is imported into Python with:
Both the complex and floating point versions of the sink take the same arguments using the following class constructor:
The following describes the arguments meanings more:
If you have successfully installed the gr-qtgui module with GNU Radio, then all of the prerequisites should be installed. Just in case, the Python modules you will need to run a QT GUI application are:
It is also recommended that you get PyQWT5 to be able to build more extensive and nicer looking GUIs.
The first step is to be able to create a qtgui sink and display it on screen. This is both the simplest and most useful for debugging. By understanding how this example works, you can go and easily add a GUI to any existing GNU Radio application to see the signals at any point in the flow graph.
Here is the full code:
Lines 1 - 7 just set up the environment and modules, including the PyQT modules we require. Lines 9 - 11 simply set up the "my_tb" class as a GNU Radio top block class and initialize it.
Line 14 is the first deviation from normal GNU Radio flow graphs. This line gets a reference to the qApp, which is QT global application element. Right now, it is enough to know that we require it, but we won't do anything with it until later.
Line 16 just sets a variable for the FFT size. Lines 18 - 22 build the blocks of the flow graph, including the qtgui block. In this flow graph, we create a sine wave and add noise to it. The noise is to make sure the signal is constantly changing in the display as a simple sine wave looks like nothing changes between frames. There is a threshold block so the GUI is not trying to run at full speed, too. Finally, the sink is a complex qtgui sink with just the first two arguments given. As can be seen in the class constructor listed above, all of the other arguments have defaults, so we will use these for now.
Lines 24 - 26 just connect all of the blocks. Like any other block, the qtgui sink is added as just another connection.
Lines 29 and 30 are specific to making the qtgui blocks visible. We have to use the "show" operation on the qtgui block, but first, we have to convert it to a Python object. Line 29 does the conversion by using the SIP wrapper interface to go from a PyObject in C++ to a native Python object as a QWidget. The "pyqwidget" method of the qtgui sink passes the proper object pointer back to allow this handling. Now, the Python object has the "show()" method required to display the sink that is called in Line 30. Without this, the code would run, but we would see nothing displayed.
The final bit of tickery that deviates from a normal flow graph is how we tell the class to run. Line 33 instantiates an object of our "my_tb" class. Instead of calling "run()" on this object, though, we only call "start()" in line 34, which is non-blocking (run() performs both a start() and wait() call). We then tell the qApp that we got a reference to in Line 10 to execute with the "exec_()" method on line 35. This starts the QT runtime engine to handle the display and controls of the QT widgets. Now, when we run the program, we should see a QT application with a widget displaying the frequency domain. [SHOWPCITURE]
The big take-aways message here is the relatively minor changes required to make a qtgui application from a flow graph.
注：Tutorial - Using the QT GUI Blocks in GNU Radio （原文出处，翻译整理仅供参考!）