My First Qt Program Running on a Linux Development Board

My First Qt Program Running on a Linux Development Board

Abstract: Learning Linux is not difficult; the challenge lies in finding the right tutorials and having someone to guide you quickly. After purchasing a development board, it often ends up gathering dust. Watching videos becomes tedious, and understanding the documentation is too hard, making it quite frustrating!

Therefore, today I will explain the basic steps to run a Qt program on the ZhiDian Atom Linux development board in a simple and easy-to-understand manner, aiming to help beginners get their first program running in half a day (this article is mainly targeted at beginners; experienced developers can skip it).

Hardware: ZhiDian Atom Linux mini development board
Software: Windows 10, VMware, Ubuntu, Qt Creator

The running effect is shown in the figure below, which is a <span>serialport</span> example running on the default UI interface of ZhiDian Atom.

My First Qt Program Running on a Linux Development Board

First, let me share my feelings about starting with Linux embedded development. When learning STM32, I became familiar with the Keil or IAR integrated development environments and could control a pin using simple registers.

After starting Linux development, I was initially intimidated by the installation images that were dozens of gigabytes, feeling that compiling Linux was particularly complex and difficult. Additionally, the numerous commands with hundreds of characters were overwhelming for someone used to graphical development. Moreover, the seller’s videos often lasted for dozens of hours, divided into several parts covering driver development, application development, Qt development, etc.

My First Qt Program Running on a Linux Development Board

Each video is long and tedious. I originally bought the board to play around, but after realizing I had to watch so many videos, I lost interest and went from being a beginner to giving up, leaving the board to gather dust.

The purpose of this article is to help everyone set aside the videos and condense the hours of video content into a single article, allowing you to quickly experience the joy of embedded Linux development! Of course, I also suggest that the official team create a quick start tutorial to help developers quickly enjoy the fun, which I believe would be more effective!

1. Download Materials

First, go to the ZhiDian Atom forum to download the materials. Be careful not to download the videos; you can watch them anytime on Bilibili, and no one would be so bored as to download the videos!

My First Qt Program Running on a Linux Development BoardMost materials are on Baidu Cloud. If you are not a member, the download speed will be slow. It is recommended to purchase a temporary membership for faster downloads, and then proceed to the next step.

2. Install Virtual Machine

The installation of the virtual machine is covered in most of ZhiDian Atom’s PDF tutorials, so I won’t elaborate further. If the article is unclear, you can also watch videos on Bilibili.

My First Qt Program Running on a Linux Development Board

I recommend beginners to carefully watch it once. If you make a mistake during installation, it’s no big deal; just delete it and reinstall.

During the installation of Ubuntu, it is highly recommended to directly download the pre-packaged Qt Creator image from ZhiDian Atom. After installing this image, you won’t need to configure it step by step. For those who need to quickly run their first Linux program, this can help avoid the confusion of learning too many details. Skipping these tedious steps allows us to quickly understand the entire development process from a global perspective.

What does this mean? It means that your newly installed Ubuntu does not have any environment or software, and you need to install everything yourself, which is quite troublesome. However, you can use the Ubuntu system that ZhiDian Atom has packaged; they have packaged this system for you, and you only need to install their packaged system on your virtual machine. How amazing is that? You can install someone else’s computer system on your own computer! Where can you find this system?

My First Qt Program Running on a Linux Development Board

After downloading, it looks like this:

My First Qt Program Running on a Linux Development Board

Then, follow the instructions here to install the system that ZhiDian Atom has packaged for you.

My First Qt Program Running on a Linux Development Board

File name: [ZhiDian Atom] I.MX6U Virtual Machine User Manual V1.3.pdf

3. Configure Network Environment

After installing Ubuntu, you may not be able to connect to the internet. This issue varies for everyone, so I recommend following ZhiDian Atom’s tutorial to ensure that your Windows, Ubuntu, and development board are all properly networked. You can refer to: [ZhiDian Atom] I.MX6U Network Environment TFTP & NFS Setup Manual V1.3.1.pdf

My First Qt Program Running on a Linux Development Board

If the document is unclear, there are also videos available, and you can follow along step by step.

My First Qt Program Running on a Linux Development Board

So, you don’t need to worry about the network part.

4. Install Qt Creator

Similarly, you can refer to: [ZhiDian Atom] I.MX6U Embedded Qt Development Guide V1.1.pdf for installing Qt Creator software.

My First Qt Program Running on a Linux Development Board

After installing Qt Creator on Ubuntu, you can write programs just like you would on Windows and run them on Ubuntu.

However, our goal is to run the Qt software on our ARM development board, right? At this point, we naturally think of installing a compilation tool on Ubuntu to compile the program into code that can run on the ARM development board. This is called a “cross-compilation toolchain”.

The term “cross” in cross-compiler means compiling code for a different architecture on one architecture, effectively crossing two architectures. Our computer is x86 architecture, while the development board is ARM architecture.

5. Install Qt Cross-Compiler

You can refer to: [ZhiDian Atom] I.MX6U Factory System Qt Cross-Compilation Environment Setup V1.6.pdf for the first chapter on installing the cross-compiler. You must install this to compile code that can run on the ARM development board in Ubuntu.

Note: This step is essential, and you must follow the tutorial step by step!

My First Qt Program Running on a Linux Development Board

5.1 Copying the Compiler

Copy the development board CD A-Basic Materials->5. Development Tools->1. Cross Compiler->fsl-imx-x11-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh

Copy it to the Ubuntu virtual machine.

You can use <span>MobaXterm</span> software for copying. You can refer to this article for its usage: 2022 First Article, All-in-One Terminal Tool MobaXterm

My First Qt Program Running on a Linux Development Board

As shown in the figure, this article has already copied the cross-compilation tool to the Ubuntu virtual machine.

My First Qt Program Running on a Linux Development Board

Execute the following command to modify the script’s permissions. After modifying the permissions, you will see the script’s color change, indicating success.

chmod u+x fsl-imx-x11-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh

Run the script to install the cross-compilation tool. Press Enter twice to confirm, then enter your user password.

The installation directory will be the default directory specified by the script, and subsequent kernel compilation environments will operate based on this installation directory.

My First Qt Program Running on a Linux Development Board

5.2 Configure Environment Variables

We know that in Linux, to run an executable file, you need to open a terminal in the corresponding directory and run it with the <span>./</span> command. But what if we want to run a specific program from another folder?

Of course, you can do that by using environment variables. Yes, environment variables are also needed in Linux! Their function is exactly the same as in Windows, which is to simplify a very long directory. Before having environment variables, the command we needed to input was:

/aaa/bbb/ccc/ddd/eee/fff/hhh/xxx.sh

With environment variables, the command we input becomes this, which is the difference. Environment variables let the system know that no matter where you call the xxx.sh command from, it refers to a specific program in a certain folder.

xxx.sh

The method to set environment variables is<span>source /opt......</span> We open a terminal in the project directory and then run the environment variable.

source /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi 
My First Qt Program Running on a Linux Development Board

Next, use the <span>env</span> command to check the environment variables. If you see these configuration options, it means you have successfully set the newly installed “cross-compilation toolchain” to the environment variables.

My First Qt Program Running on a Linux Development Board

Using the command <span>arm-poky-linux-gnueabi-gcc -v</span> allows you to check the gcc version, indicating that the environment variable is now effective.

My First Qt Program Running on a Linux Development Board

OK, your Qt cross-compiler is now installed.

5.3 Install Cross-Compilation Environment

So far, you have only installed the cross-compiler on Ubuntu. To compile Qt applications to run on the development board, you also need to set up a cross-compilation environment. Programs compiled with the ARM platform cross-compiler can run on the I.MX6U development board.

The main task is to configure Kits in Qt Creator. A Kit refers to a development and compilation environment suite, allowing you to set up different suites for different platforms and compile applications for different platforms, which validates Qt’s cross-platform capabilities! If you have installed the Android suite, you can also run Qt programs on your phone.

Reference document: [ZhiDian Atom] I.MX6U Factory System Qt Cross-Compilation Environment Setup V1.6.pdf section 2.3.

Here, we need to write a command in the script to enable the environment variable. First, open this script.

sudo vi /opt/Qt5.12.9/Tools/QtCreator/bin/qtcreator.sh

As shown in the figure, insert the following command at the first line of <span>qtcreator.sh</span>.

source /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
My First Qt Program Running on a Linux Development Board

Save the script file (ESC : wq). Use the following command to open Qt Creator. The “&” symbol is used to run it in the background.

/opt/Qt5.12.9/Tools/QtCreator/bin/qtcreator.sh &amp;
My First Qt Program Running on a Linux Development Board

5.4 Install Kits

After installing Qt Creator, there is only one default kit. Follow the tutorial to set up the other two kits.

Among them, ATK-I.MX6U is used for running on the i.MX6ULL ARM platform; IMX6U-rsync is used for network debugging and downloading programs to the development board. After compiling in Qt Creator, clicking run will directly display your program’s effect on the development board.

My First Qt Program Running on a Linux Development Board

In Qt Creator, by default, programs are sent to the board using sftp or rsync. Since the ZhiDian Atom I.MX6U factory Qt file system (version 1.9 and later) includes the rsync command, this method can be conveniently used for Qt remote debugging.

First, we need to check the current factory file system version by executing the following command on the factory system.

cat /etc/version
My First Qt Program Running on a Linux Development Board

If the file system is not version 1.9 or does not support the rsync command, please download the latest factory system from the cloud and use the latest system.

Set Static IP for Development Board

Since the LAN8720PHY network chip does not have a MAC address, a random MAC address is generated for network use at system startup. This results in a different IP address being obtained each time the board is powered on.

(The version 2.3 file system has fixed a random MAC address, which will not change on each boot; please update to the latest file system.)

Therefore, we need to set a static IP that does not change with the MAC address. The simplest method is to directly assign an IP address to it. We can add the following lines to the <span>/etc/rc.local</span> file in the factory file system as shown in the figure.

vi /etc/rc.local

Add the following content, and please set the corresponding IP address based on your router’s network segment. The following example sets a static IP address for eth0. Please ensure this IP does not conflict with other devices!

PATH=/sbin:/bin:/usr/sbin:/usr/bin
ifconfig eth0 192.168.1.115 netmask 255.255.255.0
route add default gw 192.168.1.1
echo "nameserver 114.114.114.114" &gt; /etc/resolv.conf
My First Qt Program Running on a Linux Development Board

After this, every time the development board connects to the network and powers on, its IP address will be <span>192.168.1.115</span>.

Next, refer to [ZhiDian Atom] I.MX6U Factory System Qt Cross-Compilation Environment Setup V1.6.pdf section 2.5.1 to complete the installation of the rsync method for Qt remote debugging kits.

My First Qt Program Running on a Linux Development Board

6. Practical Implementation

We open the example provided by ZhiDian Atom, taking Qt/03/03_serialport as an example. Double-click <span>03_serialport.pro</span>.

My First Qt Program Running on a Linux Development Board

After opening, select the IMX6U-rsync kit:

My First Qt Program Running on a Linux Development Board

After opening, the software will automatically compile, and generally, there are no errors. Just click the green triangle at the bottom left to compile and run.

My First Qt Program Running on a Linux Development Board

Then, you will see a magical scene on the development board: your host program is running on the development board, and you can happily play with the serial port on the development board.

Note: Since the development board has ZhiDian Atom’s boot Qt desktop, you can disable it from displaying; refer to the following:

My First Qt Program Running on a Linux Development Board

The final effect is as follows:

My First Qt Program Running on a Linux Development Board

How about that? You may not know why you are doing this, but the fastest way to learn something new is to start playing with it; reverse learning can increase your interest in learning!

Source: Guo Guo Xiao Shidi

Friendly Reminder:

Due to recent changes in the WeChat public platform’s push rules, many readers have reported not seeing updated articles in a timely manner. According to the latest rules, it is recommended to click “Recommend Reading, Share, Collect” more often to become a regular reader.

Recommended Reading:

  • Who is the strongest worker? This type of developer has an average monthly salary exceeding 30,000 yuan.

  • Are we at odds? Economic experts list the “ten sins” criticizing the iPhone 14.

  • A well-known car company had nearly 300,000 customer information leaked, all due to a developer’s mistake?

Please click “View” to give the author a thumbs up.

My First Qt Program Running on a Linux Development Board

Leave a Comment