当前位置:网站首页>[turn] flying clouds_ Qt development experience
[turn] flying clouds_ Qt development experience
2022-06-11 06:33:00 【Quiet Zhiyuan 2021】
【 turn 】 Flying clouds _Qt Development experience
Link to the original text :https://blog.csdn.net/sinolover/article/details/121392753
One 、 Development experience
01:001-010
When a large number of errors are found in the compilation , We should start from the first one , One by one solution , Don't rush to see the next mistake , Often the latter mistakes are caused by the former ones , After the first one, it's likely to be solved .
Timers are a good thing , Learn to use it well , Sometimes used QTimer::singleShot Single timer and QMetaObject::invokeMethod Can solve unexpected problems . For example, a time-consuming operation is loaded when the form is initialized , It is easy to display the main interface of the card , The interface will not be displayed until after loading , This is too laggy to experience. , At this point, you can load the time-consuming ( Sometimes these loads must be in the main thread , For example, use QStackWidget Stack form loads some subforms ), Load late or asynchronously , This will be executed after the interface is displayed , Instead of the card main interface .
// Asynchronous execution load function
QMetaObject::invokeMethod(this, “load”, Qt::QueuedConnection);
// Time delay 10 Execution in milliseconds load function
QTimer::singleShot(10, this, SLOT(load()));
Default QtCreator It's single threaded compilation , At the beginning of the design, it may be considered that the system resources should not be occupied as much as possible , And today's computers are multi-core , Default msvc The compiler is multithreaded and does not need to be set manually , For other compilers , You need to set it manually .
Method 1 : In the build settings of each project ( You can check one shadow build Where is your page ) Of build step ,make arguments Add a row -j16 that will do , This setting will be saved in pro.user In file , Once removed, it needs to be reset , This method is not recommended ;
Method 2 : Add... To the build suite environment , Tools -> Options -> Build Suite (kits)-> Select a build Suite ->environment-> On the right side change Button -> Fill in the open input box with MAKEFLAGS=-j4 , So you don't have to set up multithreaded compilation every time , This compilation parameter will be added to any project that applies the component suite ;
Be careful :-j Then the core number of the computer , Too much writing doesn't work , Look at the parameters of the computer , Or fill in a -j4 Just go , After all, computers now 4 The core should be the most basic ;
Probably from 2019 A new version of QtCreator By default, multithreading compilation will be set automatically according to the core of the computer , For example, recognize that your computer is 16 The core will be set by default -j16 Parameter compilation ;
If you want to take advantage of QtCreator Deploy Android programs , First you have to be in the AndroidStudio Internal configuration succeeded , Level all the holes .
A lot of times I find Qt After corresponding encapsulation method , Remember to take a look at the overload of this function , Multiple parameters , You will find a different world , Sometimes I suddenly realize , original Qt It's sealed for us , such as QString、QColor The overload parameters of are extremely rich .
Can be in pro Mark the version number in the document +ico Icon (Qt5 To support ), Actually in windows Up is qmake This information will be automatically converted into rc file .
VERSION = 2025.10.01
RC_ICONS = main.ico
The administrator runs the program , Limit to MSVC compiler .
QMAKE_LFLAGS += /MANIFESTUAC:“level=‘requireAdministrator’ uiAccess=‘false’” # Run as an administrator
QMAKE_LFLAGS += /SUBSYSTEM:WINDOWS,“5.01” #VS2013 stay XP function
The debug output window is attached to the run file , This is very useful , A lot of times when we release the program phase , We will encounter the program double-click can not run, also do not report an error prompt ( Everything is OK on the development machine ), I don't know what happened , Even the task manager can see it running, but no interface pops up , At this point, we need to be in the pro Add this to the file , The program with interface will also automatically pop up the debug window and print out information , Easy to find questions , Generally, programs that can't run normally will print some prompt information, such as what's missing .
TEMPLATE = app
MOC_DIR = temp/moc
RCC_DIR = temp/rcc
UI_DIR = temp/ui
OBJECTS_DIR = temp/obj
# The following line is used to set the run file with debug output window
CONFIG += console
Draw a tiled background QPainter::drawTiledPixmap, Draw a rounded rectangle QPainter::drawRoundedRect(), instead of QPainter::drawRoundRect();
Remove old styles
// Remove the original style
style()->unpolish(ui->btn);
// There must be the following line, otherwise it will not be unloaded
ui->btn->setStyleSheet("");
// Reset the style of the new control .
style()->polish(ui->btn);
02:011-020
Get the properties of the class
const QMetaObject *metaobject = object->metaObject();
int count = metaobject->propertyCount();
for (int i = 0; i < count; ++i) {
QMetaProperty metaproperty = metaobject->property(i);
const char *name = metaproperty.name();
QVariant value = object->property(name);
qDebug() << name << value;
}
Qt The built-in icon is encapsulated in QStyle in , About 70 icons , You can use it directly .
SP_TitleBarMenuButton,
SP_TitleBarMinButton,
SP_TitleBarMaxButton,
SP_TitleBarCloseButton,
SP_MessageBoxInformation,
SP_MessageBoxWarning,
SP_MessageBoxCritical,
SP_MessageBoxQuestion,
…
// Take it out and use it like this
QPixmap pixmap = this->style()->standardPixmap(QStyle::SP_TitleBarMenuButton);
ui->label->setPixmap(pixmap);
Load according to the number of bits of the operating system
win32 {
contains(DEFINES, WIN64) {
DESTDIR = KaTeX parse error: Expected 'EOF', got '}' at position 18: …D/../bin64 }̲ else { …PWD/…/bin32
}
}
Qt5 Enhanced a lot of security validation , If appear setGeometry: Unable to set geometry, Please move the visibility of the control after adding the layout .
You can put the control A Add to layout , And then the control B Set the layout , This flexibility improves the composability of controls , For example, you can add a search button to the left and right of the text box , Button to set the icon .
QPushButton *btn = new QPushButton;
btn->resize(30, ui->lineEdit->height());
QHBoxLayout *layout = new QHBoxLayout(ui->lineEdit);
layout->setMargin(0);
layout->addStretch();
layout->addWidget(btn);
Yes QLCDNumber Control to set the style , Need to put QLCDNumber Of segmentstyle Set to flat, Or you'll find that it doesn't work .
Clever use findChildren You can find all the child controls under this control . findChild To find a single .
// Find the specified class name objectName Control for
QList<QWidget *> widgets = fatherWidget.findChildren<QWidget *>(“widgetname”);
// Find all QPushButton
QList<QPushButton *> allPButtons = fatherWidget.findChildren<QPushButton *>();
// Find the first level child control , Otherwise, all the child controls will be traversed all the time
QList<QPushButton *> childButtons = fatherWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildrenOnly);
Clever use inherits Judge whether it belongs to a certain kind .
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits(“QTimer”); // returns true
timer->inherits(“QObject”); // returns true
timer->inherits(“QAbstractButton”); // returns false
Use the weak attribute mechanism , You can store temporary values for passing judgment . Can pass widget->dynamicPropertyNames() List all weak attribute names , And then through widget->property(“name”) Take out the value of the corresponding weak attribute .
At development time , Whether it's for the convenience of maintenance , Or to save memory resources , There should be one qss File to store all the style sheets , Instead of putting setStyleSheet It's all over the place . If it's the beginning stage or the testing stage, you can directly UI Right click to set style sheet , Formal projects are still suggested to be unified into one qss Style sheet files are better , Unified management .
03:021-030
If appear Z-order assignment: is not a valid widget. Error message , Use Notepad to open the corresponding ui file , Find the empty space , Delete it .
Be good at using QComboBox Of addItem The second parameter sets the user data , Can achieve a lot of results , Use itemData out .
If used webengine modular , Bring... With you when you release the program QtWebEngineProcess.exe+translations Folder +resources Folder .
Default Qt It's a form, a handle , If you want each control to have its own handle , Settings a.setAttribute(Qt::AA_NativeWindows);
Qt+Android Prevent the program from being closed .
边栏推荐
- Quantitative understanding (Quantitative deep revolutionary networks for effective information: a whitepaper)
- Redux learning (I) -- the process of using Redux
- 山东大学项目实训之examineListActivity
- Shandong University machine learning final 2021
- instanceof到底是怎样判断引用数据类型的!
- Verilog realizes binocular camera image data acquisition and Modelsim simulation, and finally matlab performs image display
- Convert text label of dataset to digital label
- MMEditing中超分模型训练与测试
- Wechat applet (authorized login of TP5)
- 021-MongoDB数据库从入门到放弃
猜你喜欢

Graphsage paper reading

Eureka集群搭建

C语言大战“扫雷”

Why don't we have our own programming language?

MongoDB安装

Record the first data preprocessing process

verilog实现双目摄像头图像数据采集并modelsim仿真,最终matlab进行图像显示

Shandong University machine learning experiment 7 pca+ SVM face recognition

Zvuldrill installation and customs clearance tutorial

Jenkins different styles of project construction
随机推荐
Handwritten promise [04] - then method chain call to recognize promise object self return
不引入第三个变量,交换两个值
Markdown + typora + picgo experimental report template attached
What are the differences and usages of break and continue?
jenkins-凭证管理
572. 另一个树的子树
538. convert binary search tree to cumulative tree
Detailed installation instructions for MySQL
538.把二叉搜索树转换成累加树
Redux learning (II) -- encapsulating the connect function
arguments......
Record the first data preprocessing process
The difference between call and apply and bind
A multi classification model suitable for discrete value classification -- softmax regression
Matlab实现均值滤波与FPGA进行对比,并采用modelsim波形仿真
搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
数组去重。。。。
C语言大战“扫雷”
JS judge whether the year is a leap year and the number of days in the month
Teach everyone how to implement an electronic signature