Programming history of my aerial Helicopter Control Base Station Software (2.1)

Source: Internet
Author: User

In the past few days, I have to stop my work due to several exams and the opening Cup National Finals! Now all the annoying things have passed. Continue! In the past, the exam was not important to me. Now it's different. I have already studied it. If I have to take one exam, I will leave it empty!

Developed with qtcreatorProgramThe project directory cannot be empty or Chinese characters.

Qt version management:

Qt_creator allows you to install multiple versions at the same time and easily switch versions.

Qt creator can automatically select the version in the system environment change. If we think that the QT version in the system environment variable is appropriate, we do not need to perform any version switch operation. Otherwise, you can add other versions by usingTools-> options...-> QT versions.If you use mingw on Windows to compile QT, you need to tell the QT creator mingw directory. SameTools-> options...-> qt4-> QT versions-> mingw directoryTo set the mingw directory.

Once QT creator is installed on Windows, the installer automatically configures the system environment variables. Generally, you do not need to manually configure the system environment variables. If QT is not set in the system environment variablesTools->OptionsTo set system environment variables.

To create a new default project, you must compile the default QT version.

 

 

Write a simple QT routine-text finder ):

Step 1: Create a new project

Create a qt4 GUI application and select qwidget as the base class of text finder. Enter textfinder in the class name and click OK. Finally, five files are generated:

Textfinder. Pro

Textfinder. UI

Textfinder. h

Textfinder. cpp

Main. cpp

 

Step 2: design the interface and generate the correspondingCodeAnd implement the search function.

2.1 design the user interface (here, I personally think the QT interface is much better than that of MFC !)

In the project browsing window, double-click textfinder. UI to bring up the interface design window.

For example, use a qlabel, qlineedit, qpushbuton, findbutton, and qtextedit. Use a qgridlayout to layout qlabel, qlineedit, and qtextedit. Use qvboxlayout to layout qtextedit and qgridlayout.

After the design, as shown in (how? It is much better than MFC! Haha ):

 

Next, process the header file. The textfind. h file already contains some required code, such as the pair des, a constructor, A destructor, and UI object. We need to add a private slot and on_findbutton_clicked () to process the find operation. Add a private function loadtextfile () to read and display the content of qtextedit. The Code is as follows:

Private slots:
Void on_findbutton_clicked ();

PRIVATE:
Ui: textfinder * UI;
Void loadtextfile ();

2.3 process source files

First, implement the loadtextfile () function in textfinder. cpp. The code snippet is as follows:

Void textfinder: loadtextfile ()
{
Qfile inputfile (":/input.txt ");
Inputfile. Open (qiodevice: readonly );

Qtextstream in (& inputfile );
Qstring line = in. readall ();
Inputfile. Close ();

UI-> textedit-> setplaintext (line );
Qtextcursor cursor = UI-> textedit-> textcursor ();
Cursor. moveposition (qtextcursor: Start, qtextcursor: moveanchor, 1 );
}

In the above Code, qfile is used to open the text file, qtextstream is used to read the text, and setplaintext () is used to display the text to textedit (). so in textfinder. CPP must contain qfile and qtextstream, as shown below:

# Include <qtcore/qfile>
# Include <qtcore/qtextstream>

 

2.4 Slot Handling

In slotIn on_findbutton_clicked (), we use the find () function to find the string to be searched. The code snippet is as follows:

Void textfinder: on_findbutton_clicked ()
{
Qstring searchstring = UI-> lineedit-> text ();
UI-> textedit-> Find (searchstring, qtextdocument: findwholewords );
}

 

Finally, after completing the above functions, we need to call them in the constructor.Loadtextfile (), the Code is as follows:

Textfinder: textfinder (qwidget * parent)
: Qwidget (parent), UI (new UI: textfinder)
{
UI-> setupui (this );
Loadtextfile ();
}

 

You needUi_textfinder.h file, which is generated by the interface file during compilation. This file is not available before compilation, and the inclusion "ui_textfinder.h" in textfinder. cpp also prompts that the ui_textfinder.h file cannot be found. This problem disappears when ui_textfinder.h is generated after compilation!

Step 3: Add a resource file

To the above, the compilation can be passed, but it cannot be run after compilation, prompting"Exited with code 0 .". It is estimated that no text file is added"Input.txt.

Next, add the resource file step by step:

Click file-> New-> resource file-> OK. In the name column, enter "textfinder. qrc ",

Click "Next ",

Click "finish ".

In the project window, double-click "textfinder. Pro" and click "add"-> "add prefix" on the right ". Set the prefix directory and click "add"-> "add files" to add the corresponding resource file.

 

Step 4: Compile and run

 

Finished !!!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.