Qt Tutorial 01

 

Qt is one of the most widely used libraries in C++ GUI programming and has cross-platform features.

Qt can run not only on windows, but also on Linux,

You can even develop Android applications with Qt.

 

Qt's commonly used development environment is Qt Creator. Qt Creator integrates compilers, editors, and debugging tools.

Of course, you can also develop with a text editor + compiler.

This series uses qt-opensource-windows-x86-mingw492-5.6.1-1.

 

The following introduces the basic content of Qt through a simple example.

 

Create a new Qt Widgets Application.

You can see that the project includes the following files

Among them, hello.pro is the project information, *.h is the C++ header file, *.cpp is the C++ source file, and *.ui is the interface file.

Double-click any file to enter the edit page for that file.

Double-click the ui interface file to enter the design mode.

On the left is the control bar, which can be dragged into the design interface in the middle.

The properties of each control can be edited through the property bar in the lower right corner, and the text displayed by the control can be adapted by modifying the text property.

The displayed text can also be modified by double-clicking.

 

Right-click the [Calculate] button, go to the slot, and select click()

Enter the following code

void MainWindow::on_pushButton_clicked()
{
    bool ok;
    double r;
    double area;
    QString valueStr;
    QString tempStr;

    valueStr = ui->lineEdit->text();
    r = valueStr.toDouble(&ok);
    area = PI*r*r;
    ui->label_3->setText(tempStr.setNum(area));
}

 

Compile, run.

Finish.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325248303&siteId=291194637