First, the development of lessons learned
When the compiler found a large number of errors, starting from the first look, one by one to solve, do not rush to see the next error, often behind the errors are due to the previous errors caused after the first solution is likely to have solved.
Timer is a good thing, learn to use it well, sometimes with QTimer :: singleShot can solve unexpected problems.
Open creator, an increase in the construction kit MAKEFLAGS = -j8 environment, you can not set a time multi-threaded compilation. Time and cherish life. The default is to have the new version of QtCreator j8.
If you want to successfully deploy Android program by QtCreator, first you have to configure successfully AndroidStudio inside the pit level all times.
Methods Qt corresponding to the package to find a lot of time, remember to look at the function overloading, multiple parameters, you will find a different world, sometimes suddenly realized that Qt has helped us a good package.
- Pro file can be written in marker on the version number + ico icon (Qt5 is supported)
VERSION = 2018.7.25
RC_ICONS = main0.ico
- Administrator to run the program, defined in the MSVC compiler.
QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\" #以管理员运行
QMAKE_LFLAGS += /SUBSYSTEM:WINDOWS,\"5.01\" #VS2013 在XP运行
Run the file with debugging output window
CONFIG + = console proDrawing tiled background QPainter :: drawTiledPixmap
draw rounded rectangle QPainter :: drawRoundedRect (), instead of QPainter :: drawRoundRect ();- Remove the old style
//移除原有样式
style()->unpolish(ui->btn);
//重新设置新的该控件的样式。
style()->polish(ui->btn);
- Obtain property 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 built-in icon encapsulated in QStyle, probably more than seventy icons can be directly used.
QStyle :: SP_TitleBarMenuButton- The operating system determines the number of bits loaded
win32 {
contains(DEFINES, WIN64) { DESTDIR = $${PWD}/../../bin64
} else { DESTDIR = $${PWD}/../../bin32 }
}
Qt5 much enhanced security verification, if setGeometry appears: Unable to set geometry, move the control to be seen after the addition of layout.
- A control may be added to the layout, and the layout of the controls set B, which greatly improves the flexibility of the control composition, may be added such as a search button on the right the left text box, a button icon is provided.
QPushButton *btn = new QPushButton;
btn->resize(30, ui->lineEdit->height());
QHBoxLayout *layout = new QHBoxLayout(ui->lineEdit);
layout->setMargin(0);
layout->addStretch();
layout->addWidget(btn);
Set the style of QLCDNumber control, you need to set the segmentstyle QLCDNumber is flat.
- Clever use findChildren can find all the child controls in the control. findChild to look for a single.
//查找指定类名objectName的控件
QList<QWidget *> widgets = parentWidget.findChildren<QWidget *>("widgetname");
//查找所有QPushButton
QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();
//查找一级子控件,不然会一直遍历所有子控件
QList<QPushButton *> childButtons = parentWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildrenOnly);
- Clever use determines whether a certain class inherits.
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
A weak property mechanism, may store temporary values determined for delivery.
In the development, both for ease of maintenance, or consider saving memory resources, we should have a qss file to store all the style sheets, and should not be setStyleSheet written everywhere.
If the Z-order assignment appears: "is not a valid widget error messages, use Notepad to open the corresponding ui files found.
The place is empty, delete it. QComboBox addItem good use of the second user data parameters, many effects can be achieved using itemData taken out.
If the webengine module, when the publisher belt QtWebEngineProcess.exe + translations folders + resources folder.
a.setAttribute (Qt :: AA_NativeWindows); allows each control has a separate handle.
- Qt + Android prevent the program is closed.
#if defined(Q_OS_ANDROID)
QAndroidService a(argc, argv);
return a.exec()
#else
QApplication a(argc, argv);
return a.exec();
#endif
May be provided on the overall style indicator, e.g. ::-Down arrow arrow, ::} {MENU-Indicator :: up-arrow arrow: Disabled, :: up-arrow arrow: OFF {}.
- Set the background image position can be performed.
QMainWindow > .QWidget {
background-color: gainsboro;
background-image: url(:/images/pagefold.png);
background-position: top right;
background-repeat: no-repeat
}
Run the Qt4 Qt embedded linux program written: ./ HelloQt -qws & Qt5 wording: ./ HelloQt --platform xcb
Qtcreator software configuration files are stored in: C: \ Users \ Administrator \ AppData \ Roaming \ QtProject, sometimes if we find a problem, after deleting this folder to open the creator automatically regenerated.
QMediaPlayer dependent local decoder, download k-lite or LAV Filters mounted to the WIN.
Code judgment MSVC compiler version, if (_MSC_VER == 1800), the correspondence between 2013 = 18,002,012 = 17,002,010 = 16,002,008 = 15,002,005 = 1400
Analyzing the different platforms in pro: message ($$ QT_ARCH) contains (QT_ARCH, arm).
- Qt minimize recovery after freezing suspended animation interface, plus the code
void showEvent(QShowEvent *e){
setAttribute(Qt::WA_Mapped);
QWidget::showEvent(e);
}
Obtaining the title bar height: style () -> pixelMetric (QStyle :: PM_TitleBarHeight); PM_TitleBarHeight point inside you'll find the New World.
- Set the high score screen and other property to support 2K4K high resolution, especially in the mobile phone app. It must be written in QApplication main function a (argc, argv); previously.
#if (QT_VERSION > QT_VERSION_CHECK(5,6,0))
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
If you run the program appears Fault tolerant heap shim applied to current process . This is usually due to previous crashes. Error.
Way: open the registry, find the HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows NT \ CurrentVersion \ AppCompatFlags \ Layers, select Layers key, delete your own path to the program from the list on the right.Qt built form QFormLayout form layout for combining the interface to automatically generate the label + input box.
qml play the video in linux need to install sudo apt-get install libpulse-dev.
You can inherit directly QSqlQueryModel implement custom QueryModel, a column such as font color, placeholders, like other styles, rewriting QVariant CustomSqlModel :: data (const QModelIndex & index, int role) const.
- After Qt5 provides classes QScroller directly to the scrolling control.
ui->listWidget->setHorizontalScrollMode(QListWidget::ScrollPerPixel);
QScroller::grabGesture(ui->listWidget,QScroller::LeftMouseButtonGesture);
- If you do not want to use sqlite database to generate a database file, you can create in-memory database.
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
Clearing the data table and reset the increment ID, sql = truncate table table_name.
Qtchart minimum module requirements Qt5.4.
QPushButton left-aligned text, the style sheet to set QPushButton {text-align: left;}
Do not doubt this part of the dog ate ^ _ ^ middle section to be updated, it will be continuously updated. Also welcome message at the bottom of the article added.
Chinese garbage problem Qt community, many versions of how to choose the installation package issues, how to package the publisher of the problems caused, called the three big mountains Qt community!
Examples example in the installation directory under Qt, completion of reading, starting salary 20K.
80% of all because of the collapse of either cross-border or uninitialized, Sikou these two points, 80% of the issue is resolved.
I generally reserved four versions, for compatibility with qt4 4.8.7, the final support XP version 5.7.0, the latest version 5.9.8 of long-term support, such as the highest new version 5.12.3.
Ultimate Cheats: If you can not find the answer to encounter problems Qt search terms, try starting with keywords android with JAVA C #, you will find a paradise on earth, others probably did!
The last one: cherish life, away from programming. I wish you all thick hair, good sleep, emotional stability, financial freedom!
Second, the forum recommended Qt + + personal blog site
name | Site |
---|---|
qtcn | http://www.qtcn.org |
Space beans | https://www.devbean.net |
yafeilinux | http://www.qter.org |
A two or three miles to go | http://blog.csdn.net/liang19890820 |
Utopia No. 2 | http://blog.csdn.net/taiyang1987912 |
foruok | http://blog.csdn.net/foruok |
jason | http://blog.csdn.net/wsj18808050 |
Headed for the 10 nights eight | http://www.cnblogs.com/swarmbees |
BIG_C_GOD | http://blog.csdn.net/big_c_god |
Public 孙二狗 | https://qtdebug.com/qtbook |
Amada brother | https://blog.csdn.net/ly305750665 |
Zheng Tianzuo | https://blog.csdn.net/zhengtianzuo06 |
Cold Mountain - Lay | https://blog.csdn.net/esonpo |
feiyangqingyun | https://blog.csdn.net/feiyangqingyun |
Front row pig | http://blog.csdn.net/goforwardtostep |
The column know almost Taoge | https://zhuanlan.zhihu.com/TaoQt |
Qt foreigner Video Tutorial | http://space.bilibili.com/2592237/#!/index |
Qt supplementary documentation wiki | https://wiki.qt.io/Main |
Qt source code to view the site | https://code.woboq.org/qt5 |
Third, the public micro-channel number
Welcome concern public micro-channel number] [efficient programmers, content C ++ / Python, learning, writing skills, popular technology, career development, a lot of dry goods, benefits a lot!