Experience in the development of Qt martial arts Cheats

First, the development of lessons learned

  1. 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.

  2. Timer is a good thing, learn to use it well, sometimes with QTimer :: singleShot can solve unexpected problems.

  3. 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.

  4. If you want to successfully deploy Android program by QtCreator, first you have to configure successfully AndroidStudio inside the pit level all times.

  5. 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.

  6. Pro file can be written in marker on the version number + ico icon (Qt5 is supported)
VERSION     = 2018.7.25
RC_ICONS    = main0.ico
  1. 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运行
  1. Run the file with debugging output window
    CONFIG + = console pro

  2. Drawing tiled background QPainter :: drawTiledPixmap
    draw rounded rectangle QPainter :: drawRoundedRect (), instead of QPainter :: drawRoundRect ();

  3. Remove the old style
//移除原有样式
style()->unpolish(ui->btn);
//重新设置新的该控件的样式。
style()->polish(ui->btn);
  1. 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;
}
  1. Qt built-in icon encapsulated in QStyle, probably more than seventy icons can be directly used.
    QStyle :: SP_TitleBarMenuButton

  2. The operating system determines the number of bits loaded
win32 {
    contains(DEFINES, WIN64) { DESTDIR = $${PWD}/../../bin64
    } else { DESTDIR = $${PWD}/../../bin32 }
}
  1. Qt5 much enhanced security verification, if setGeometry appears: Unable to set geometry, move the control to be seen after the addition of layout.

  2. 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);
  1. Set the style of QLCDNumber control, you need to set the segmentstyle QLCDNumber is flat.

  2. 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);
  1. 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
  1. A weak property mechanism, may store temporary values ​​determined for delivery.

  2. 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.

  3. 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.

  4. QComboBox addItem good use of the second user data parameters, many effects can be achieved using itemData taken out.

  5. If the webengine module, when the publisher belt QtWebEngineProcess.exe + translations folders + resources folder.

  6. a.setAttribute (Qt :: AA_NativeWindows); allows each control has a separate handle.

  7. 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
  1. May be provided on the overall style indicator, e.g. ::-Down arrow arrow, ::} {MENU-Indicator :: up-arrow arrow: Disabled, :: up-arrow arrow: OFF {}.

  2. 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
}
  1. Run the Qt4 Qt embedded linux program written: ./ HelloQt -qws & Qt5 wording: ./ HelloQt --platform xcb

  2. 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.

  3. QMediaPlayer dependent local decoder, download k-lite or LAV Filters mounted to the WIN.

  4. 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

  5. Analyzing the different platforms in pro: message ($$ QT_ARCH) contains (QT_ARCH, arm).

  6. Qt minimize recovery after freezing suspended animation interface, plus the code
void showEvent(QShowEvent *e){
setAttribute(Qt::WA_Mapped);
QWidget::showEvent(e);
}
  1. Obtaining the title bar height: style () -> pixelMetric (QStyle :: PM_TitleBarHeight); PM_TitleBarHeight point inside you'll find the New World.

  2. 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
  1. 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.

  2. Qt built form QFormLayout form layout for combining the interface to automatically generate the label + input box.

  3. qml play the video in linux need to install sudo apt-get install libpulse-dev.

  4. 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.

  5. After Qt5 provides classes QScroller directly to the scrolling control.
ui->listWidget->setHorizontalScrollMode(QListWidget::ScrollPerPixel);
QScroller::grabGesture(ui->listWidget,QScroller::LeftMouseButtonGesture);
  1. 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:");
  1. Clearing the data table and reset the increment ID, sql = truncate table table_name.

  2. Qtchart minimum module requirements Qt5.4.

  3. QPushButton left-aligned text, the style sheet to set QPushButton {text-align: left;}

  4. 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.

  5. 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!

  6. Examples example in the installation directory under Qt, completion of reading, starting salary 20K.

  7. 80% of all because of the collapse of either cross-border or uninitialized, Sikou these two points, 80% of the issue is resolved.

  8. 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.

  9. 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!

  10. 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!

Guess you like

Origin www.cnblogs.com/feiyangqingyun/p/10962456.html