Download Qt Creator 5.1 source
Windows Binary on SourceForge.net
This article was unplanned in the original series and will be a short diversion while I plan the next article. The content of this article will discuss a Qt version of the Open Dyno Screen application that I started earlier in the year. The work was based on a couple of requests from Linux users. They were interested in the Open Dyno project but wanted all of the applications to run on Linux. It was an interesting request but I didn't have a lot of experience working with GUI development on Linux. I have had an interest in working with Qt for a long time but never really found the opportunity do anything meaningful with it. Part of the issue was the licensing model that was previously used on the Windows platform. Since the real time application is intended to run on Linux with the RT Preempt_RT patch installed, this project seemed like the perfect opportunity to jump into researching Qt. Since Qt is designed for cross platform development, all of the Qt code runs equally well on Windows. The sample application is actually a Windows binary.
I found a series of videos on YouTube by VoidRealms that made it very easy to get started with Qt. VoidRealms made a few book suggestions in one of his Qt videos. I purchased two of the suggested books from Amazon. The first is a beginners book Foundations of Qt Development by Johan Thelin. After reading parts of this book I could see a parallel to the material that VoidRealms was covering on YouTube. The book is fairly good and provides enough basic material to get started. I found myself referencing the Internet on some sections for more detail. The second book which I haven’t read yet is called Advanced Qt Programming by Mark Summerfield. I purchased this book to better understand the model view architecture in Qt which will be beneficial when working with the SQLite database.
My goal for the project was to duplicate most if not all of the C# based screen designer in Qt /C++ using the Qt Creator IDE. I was pleasantly surprised at how productive the Qt framework is. I was torn between using the new QML based applications or the classic widget based applications. I decided on a classic widget application because I believed it would be much easier to integrate all of the required components of the Screen application. There is no reason QML couldn’t be used for some utility applications though.
The current OpenDyno C# HMI / Screen Designer was designed to be run-time configurable. The buttons, leds, charts and gauges are dropped on the screen and configured using a property editor while the application is running. The screen designer also included the ability to execute C# scripts using the CSScript library. As an open source project, the hardest part to sell was the inclusion of National Instruments Measurement Studio controls and Quantum Whale Editor.Net code editor. These two components combined cost about $1000. If you need to purchase Visual Studio it will be an additional $1000. I should mention that there are some open source alternative that can be used on the C# Windows Forms version as well and I did discuss that a little bit in the previous article. Because of the way the controls use a facade class they can be easily replaced.
Qt Screen Designer
One of the things that has stopped me from investing a lot of time developing GUI applications for Linux in the past was the lack of quality industrial type widgets and charting components. I’m not sure if there aren’t many or I’m just not able to find them. In my most recent search I discovered quite a few of them.
Now that I had found enough widgets to base the Qt application on I started putting some code together. The first thing I developed was the screen editor. The screen editor performs the basic function of allowing you to place, move and re-size widgets. Since the Qt Creator Application itself is open sourced I decided to see how it performs these operations. I found the package that had the components I was looking for in the qttools package. In the folder \src\designer\src\components\formeditor there are two files widgetselection.h and widgetselection.cpp which define the classes WidgetHandle and WidgetSelection. WidgetSelection holds eight WidgetHandles and a pointer to the selected widget. I added an additional WidgetHandle labeled as a drag handle below. Since the Open Dyno screens are designed to be modified at run-time the drag handle is over sized so that it will reduce the chance of accidentally clicking a button. I needed to do quite a bit of modifications to these classes because they were originally tightly integrated with the Qt designer.
Qt includes a built in class named QRubberBand for selecting widgets. This allows you to draw a transparent rectangle on the screen as shown below in blue. This worked out of the box without any issues. Once the rubber band is drawn you simply search in the rectangle for any contained widgets.
With the ability to select and move widgets, I started adding more of the widgets that I described earlier to the project. The screen shot below is the basic user interface that allows you to insert widgets onto the screen. To insert a widget you first put the screen into edit mode by clicking the tool bar button. Then right click on the screen to display a pop up menu that contains all the widgets.
Points of Interest
- Initial Release April 23, 2014