[Qt Summary] terminal Remote Upgrade client, qt summary terminal Client
Environment: QT4.8.5 for Windows (Qt Creator + MinGW)
I. Preface:
1. Depth: given that C/C ++ skills are far from enough, I am still focused on C/C ++, so I am not planning to continue to study Qt.
2. Why Qt: I have never done anything related to the interface before, and I have been curious about how to make the dazzling interface. Now we need an interface, and no one needs to use Microsoft's MFC. In view of this, we need to learn how to use it now (no one can ask ), C ++ GUI QT4 programming, which was bought half a year ago, was decided on Qt.
3. Content: no specific encoding is involved, and code examples are used when necessary.
4. essence: I will summarize the post. However, it may bring some inspiration or reference, maybe.
2. knowledge related to Qt (visible on the surface ):
1. QLabel
2. QLineEdit
3. QGroupBox
4. QDialogButtonBox
5. QPushButton
6. QProgressBar
7. QTableWidget
8. QTextBrowser
9. QDate, QTime, and QTimer
10. QRegExp
11. Load files on the hard disk
12. Error prompt box
13. Add a Logo for the application, change the Software Title, disable software maximization, and set the software appearance
3. One by one
- QLabel, QLineEdit, and QGroupBox:
(1) font, size, color
These can be directly set in Qt Designer
(2) display Chinese Characters
SetText (QString: fromUtf8 ("Chinese "));
(3) read the data in the input box. After the input, it is displayed in the Update log box.
For example, the remote IP field captures two signals and connects them to the same slot:
connect(ipLineEdit, SIGNAL(editingFinished()), this, SLOT(getIP()));connect(ipLineEdit, SIGNAL(textChanged(QString)), this, SLOT(getIP()));
The condition for transmitting the editingFinished () signal is to press Enter or leave the edit box,
The textChanged (QString) signal transmission condition is that the content in the editing box is changed.
In the getIP () slot, You need to filter the data that does not meet the requirements and assign the input value to the variables in the program when appropriate:
void Class::getIP(void){ QString readText = ipLineEdit->text(); /* 1-get text */ QStringList list; if(readText.compare(Server_ip) != 0) { /* 2-text changed */ list = readText.split("."); if (!readText.isEmpty() && (list.count() == 4)) { /* 3- match the value format */ /* assign here */ } else { } }}
For display, call the append () function of the QtextBrowser object directly.
For other editing boxes, perform specific operations as needed.
(4) Regular Expression QRegExp
When inputting data, you can use regular expressions to restrict the data. This greatly simplifies the code for checking application parameters and makes the programming process more focused.
For this example, the place where you need to add a regular expression is:
|
Restrictions |
Regular Expression |
Network ip address |
1. Number, decimal point 2, point value: [0,255] 3. decimal point: Divide ip into four parts |
QRegExp ip("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"); 2[0-4]\\d: 200 - 249 25[0-5]: 250 - 255 [01]?\\d\\d?:0 - 199 {3}: the content in the brackets is repeated three times. The result format is xxx. |
Network Port |
1. Pure Number 2, Max. 5 digits |
QRegExp port("^[0-9]{1,5}$"); |
SIM |
1. Only 2 and 11 digits |
QRegExp sim("^[0-9]{1,11}$"); |
2. progress bar QProgressBar:
progressBar->setMinimum(0);
progressBar->setMaximum(100);
Set the maximum and minimum values of the progress bar. When the program running Progress is displayed, you can update the progress bar display in the interface thread through the emit transmit signal.
3. QPushButton:
It mainly involves changing the font color of the button:
QPalette palet = startButton->palette();
palet.setColor(QPalette::ButtonText, QColor(75, 172, 198));
startButton->setPalette(palet);
4. Update the time QDate, QTime, and QTimer on the software.
Create a timer using QTimer to transmit an update time signal once a second, and display the time in the corresponding slot:
QDateTime dateTime = QDateTime::currentDateTime();
timeLabel->setText(dateTime.time().toString());
5、QTextBrowser
The Qt signal-slot mechanism is used here, because in multithreading:
(1) do not access the GUI from any other thread except the primary thread
(2) prohibit the parent-child relationship across threads
With the signal-slot mechanism, the GUI thread update interface is a natural solution.
6. Load files
Call the static function QFileDialog: getOpenFileName to select the file to be loaded. This function returns the selected file name (including the path); otherwise, an empty string (null string) is returned ).
This function also displays a modal file dialog for you to browse the file.
QString initName = fileLineEdit->text();if (initName.isEmpty()) { /* load file from currentPath */ initName = QDir::currentPath();}/* getOpenFileName() returns an existing file selected by the user */updateFileName = QFileDialog::getOpenFileName(this, tr("Open file"), initName);updateFileName = QDir::toNativeSeparators(CAppConfig::one.updateFileName);if (updateFileName.isEmpty()) { /* update text in the QLineEdit */fileLineEdit->setText(CAppConfig::one.updateFileName);/* do other things */} else { }
7. Error prompt box
That's right! Is QMessageBox.
This point is raised mainly based on the consideration of software humanization. Its Related content is detailed in the help document:
8. Add a Logo for the application and change the Software Title
QIcon icon("./logo.png");
setWindowIcon(icon);
SetWindowTitle (QString: fromUtf8 ("software name V1.0 "));
10. Disable the software maximization Function
setFixedSize(this->width(), this->height());
Iv. Set the software appearance Style
The reason for pulling it out is that this is a big and broad topic. In addition to the Qt interface, you can also use Open GL to draw an advanced and beautiful interface in Qt, I do not intend to go deep into it (I also want to learn C/C ++ ).
The effect is to directly add a file in "C ++ GUI QT4 programming" to your project.
QApplication::setStyle(new BronzeStyle);
V. Qt Multithreading
See another article:
[Qt learning] multi-threaded Qthread operations
Or http://no001.blog.51cto.com/1142339/277004/
Vi. Qt Network Programming
See another article:
[Qt learning] UDP Programming
7. Conclusion
In the process of playing Qt, the most amazing thing is the Qt signal-slot mechanism. With its many things, it naturally becomes. In the Bible, the saying goes: "to have light !" There is light. God said: "There must be a storm between the water, and water should be separated !" This is the case.
Qt wants to remotely control the linux system using the ssh2 protocol. Is there a qt ssh2 protocol package? Or how should we start?
I don't know the protocol package. I only know that the controlled end of the sunflower remote control software supports the linux host system and is also implemented through the SSH command line, you may wish to go to their official website to check the specific operations
Which of the following is a remote ticket for QT placement?
I opened a store in partnership with several friends with hope,
After several twists and turns, I went to many places
Still stay at "QT 1615" with confidence,
Relatively good. It took a few months, and the security was relatively high.
You can choose to pay for remote red packets.
However, the platform for email refresh is still feasible,
There are so many scammers to tell you about this place,
Try the rest of the landlords by yourself. Please accept it and score it !!
Group walk
Can you solve your problem?