qtkaifajingyan
自己总结的这十多年做Qt开发以来的经验,以及Qt相关武林秘籍电子书,会一直持续更新增加,欢迎各位留言增加内容或者提出建议,谢谢!公众号:Qt实战/Qt入门和进阶/Qt教 程
Top Related Projects
Qt5 super module
a cool QtQuick component library (一套酷炫的QtQuick基础库)
A new, customizable Arduino NMEA parsing library
Quick Overview
The "qtkaifajingyan" repository is a comprehensive collection of Qt development experiences and best practices in Chinese. It covers various aspects of Qt programming, including tips, tricks, and solutions to common problems encountered during Qt development.
Pros
- Extensive coverage of Qt development topics
- Regularly updated with new content and examples
- Written in Chinese, making it accessible to a large developer community
- Includes practical solutions to real-world Qt development challenges
Cons
- Primarily in Chinese, which may limit accessibility for non-Chinese speakers
- Some examples may be specific to certain Qt versions or environments
- Lacks a structured table of contents or clear organization
- May require prior Qt knowledge to fully utilize the content
Code Examples
This repository is not a code library but rather a collection of development experiences and best practices. Therefore, there are no specific code examples to showcase. The repository contains various code snippets and explanations within its documentation.
Getting Started
As this is not a code library, there are no specific getting started instructions. However, users can benefit from the repository by:
- Cloning or downloading the repository
- Browsing the various markdown files containing Qt development tips and experiences
- Using the search functionality in their preferred text editor or GitHub to find specific topics of interest
- Applying the shared knowledge and best practices to their own Qt projects
Competitor Comparisons
Qt5 super module
Pros of qt5
- Comprehensive Qt framework with extensive documentation and support
- Large community and ecosystem with numerous resources and third-party libraries
- Official repository maintained by Qt Company, ensuring stability and regular updates
Cons of qt5
- Larger codebase and more complex structure, potentially overwhelming for beginners
- Steeper learning curve due to its extensive features and capabilities
- Licensing restrictions for commercial use (depending on the specific version)
Code comparison
qtkaifajingyan:
void Widget::initForm()
{
this->setWindowTitle("Qt开发经验总结");
this->setFixedSize(900, 650);
QUIHelper::setFormInCenter(this);
}
qt5:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
The qtkaifajingyan repository focuses on practical Qt development experience and tips, offering a more targeted approach for Chinese developers. It provides specific examples and best practices for common Qt scenarios. On the other hand, qt5 is the official Qt framework repository, offering a comprehensive set of tools and libraries for cross-platform application development. While qt5 provides a more extensive and standardized framework, qtkaifajingyan offers a curated collection of practical knowledge and solutions for Qt developers.
a cool QtQuick component library (一套酷炫的QtQuick基础库)
Pros of TaoQuick
- More comprehensive documentation and examples
- Better support for QML and modern Qt features
- Active development with frequent updates
Cons of TaoQuick
- Steeper learning curve for beginners
- Fewer ready-to-use widgets compared to qtkaifajingyan
- Requires more setup and configuration
Code Comparison
TaoQuick:
import TaoQuick 1.0
TaoQuickItem {
id: root
width: 100
height: 100
}
qtkaifajingyan:
#include "frmmain.h"
#include "ui_frmmain.h"
frmMain::frmMain(QWidget *parent) :
QWidget(parent),
ui(new Ui::frmMain)
{
ui->setupUi(this);
}
TaoQuick focuses on QML-based development, while qtkaifajingyan primarily uses traditional Qt widgets. TaoQuick offers more modern and flexible UI development, but qtkaifajingyan provides a simpler approach for those familiar with Qt widgets.
Both projects aim to improve Qt development experience, but TaoQuick is more suited for advanced users looking to leverage the latest Qt features, while qtkaifajingyan is better for beginners or those preferring a more traditional Qt approach.
A new, customizable Arduino NMEA parsing library
Pros of TinyGPSPlus
- Specialized library for GPS parsing, offering efficient and lightweight functionality
- Well-documented with examples and clear API, making it easier for developers to integrate
- Actively maintained with regular updates and bug fixes
Cons of TinyGPSPlus
- Limited scope, focusing only on GPS functionality
- May require additional libraries or code for more complex applications
- Less suitable for large-scale Qt-based projects
Code Comparison
TinyGPSPlus:
#include <TinyGPS++.h>
TinyGPSPlus gps;
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
}
}
qtkaifajingyan:
#include <QGeoPositionInfoSource>
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->startUpdates();
}
The code snippets demonstrate the different approaches: TinyGPSPlus focuses on parsing raw GPS data, while qtkaifajingyan utilizes Qt's positioning framework for a more integrated solution in Qt applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
0 åè¨è¯´æ
- 项ç®ä½åï¼https://qtchina.blog.csdn.net/article/details/97565652
- è§é¢ä¸»é¡µï¼https://space.bilibili.com/687803542
- ç½åºå°åï¼https://shop244026315.taobao.com
- èç³»æ¹å¼ï¼QQï¼517216493ï¼å¾®ä¿¡ï¼feiyangqingyunï¼æ¨èå 微信ã
- å ¬ ä¼ å·ï¼Qtå®æ/Qtå ¥é¨åè¿é¶/Qtæç¨/Qt软件
- çæ¬æ¯æï¼ææ项ç®å·²ç»å ¨é¨æ¯æQt4/5/6ææçæ¬ä»¥ååç»çæ¬ã
- çæ§ä½åä½éªï¼https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g æåç ï¼01jf
- å ¶ä»ä½åä½éªï¼https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A æåç ï¼o05q
- çæ§ç³»ç»å¨çº¿ææ¡£ï¼http://www.qtcdev.com/video_system/
- 大å±ç³»ç»å¨çº¿ææ¡£ï¼http://www.qtcdev.com/bigscreen/
- ç©èç½ç³»ç»å¨çº¿ææ¡£ï¼http://www.qtcdev.com/iotsystem/
1 å¼åç»éª
01ï¼001-010
- å½ç¼è¯åç°å¤§éé误çæ¶åï¼ä»ç¬¬ä¸ä¸ªçèµ·ï¼ä¸ä¸ªä¸ä¸ªç解å³ï¼ä¸è¦æ¥çå»çä¸ä¸ä¸ªé误ï¼å¾å¾åé¢çé误é½æ¯ç±äºåé¢çé误å¼èµ·çï¼ç¬¬ä¸ä¸ªè§£å³åå¾å¯è½é½è§£å³äºãæ¯å¦æ们å¯è½å°±åéäºä¸è¡ä»£ç ï¼ç¼è¯æ示å ç¾ä¸ªé误ï¼ä½ åªè¦æè¿ä¸è¡çº æ£äºï¼å ¶ä»é误ä¹å°±æ²¡äºã
- å®æ¶å¨æ¯ä¸ªå¥½ä¸è¥¿ï¼å¦ä¼å¥½ä½¿ç¨å®ï¼ææ¶åç¨QTimer::singleShotå次å®æ¶å¨åQMetaObject::invokeMethodå¯ä»¥è§£å³ææ³ä¸å°çé®é¢ãæ¯å¦å¨çªä½åå§åçæ¶åå è½½ä¸ä¸ªèæ¶çæä½ï¼å¾å®¹æå¡ä¸»çé¢çæ¾ç¤ºï¼è¦å¨å è½½å®ä»¥åæä¼æ¾ç¤ºçé¢ï¼è¿å°±å¯¼è´äºä½éªå¾å¡ä¸å好çæè§ï¼æ¤æ¶ä½ å¯ä»¥å°èæ¶çå è½½ï¼ææ¶åè¿äºå è½½åå¿ é¡»å¨ä¸»çº¿ç¨ï¼æ¯å¦ç¨QStackWidgetå æ çªä½å è½½ä¸äºåçªä½ï¼ï¼å»¶æ¶æè å¼æ¥è¿è¡å è½½ï¼è¿æ ·å°±ä¼å¨çé¢æ¾ç¤ºåå»æ§è¡ï¼èä¸æ¯å¡ä½ä¸»çé¢ã
//å¼æ¥æ§è¡loadå½æ°
QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection);
//延æ¶10毫ç§æ§è¡loadå½æ°
QTimer::singleShot(10, this, SLOT(load()));
//å®æ¶å¨lambda表达å¼æ¹å¼
QTimer::singleShot(10, [&]() {
load();
});
QTimer *timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, this, [timer, this] {
});
timer->start(5000);
- é»è®¤QtCreatoræ¯å线ç¨ç¼è¯ï¼å¯è½è®¾è®¡ä¹åèèå°å°½éä¸è¿å¤å ç¨ç³»ç»èµæºï¼èç°å¨ççµèé½æ¯å¤æ ¸å¿çï¼é»è®¤msvcç¼è¯å¨æ¯å¤çº¿ç¨ç¼è¯çä¸éè¦æå¨è®¾ç½®ï¼è对äºå ¶ä»ç¼è¯å¨ï¼éè¦æå¨è®¾ç½®æè¡ã
- æ¹æ³ä¸ï¼å¨æ¯ä¸ªé¡¹ç®çæ建设置ä¸ï¼å¯ä»¥å¾éä¸ä¸ª shadow build ç页é¢å°æ¹ï¼çbuildæ¥éª¤ï¼make argumentså¢å ä¸è¡ -j16 å³å¯ï¼æ¤è®¾ç½®ä¼ä¿åå¨pro.useræ件ä¸ï¼ä¸æ¦å é¤å°±éè¦éæ°è®¾ç½®ï¼ä¸å»ºè®®æ¤æ¹æ³ï¼
- æ¹æ³äºï¼å¨æ建å¥ä»¶çç¯å¢ä¸å¢å ï¼å·¥å ·->é项->æ建å¥ä»¶(kits)->éä¸ä¸ä¸ªæ建å¥ä»¶->environment->å³ä¾§changeæé®->æå¼çè¾å ¥æ¡ä¸å¡«å ¥ MAKEFLAGS=-j4 ï¼ è¿æ ·å°±å¯ä»¥ä¸ç¨æ¯æ¬¡è®¾ç½®å¤çº¿ç¨ç¼è¯ï¼åªè¦æ¯åºç¨è¯¥æ件å¥ä»¶ç项ç®é½ä¼å ä¸è¿ä¸ªç¼è¯åæ°ï¼
- 注æï¼-jåé¢æ¥çæ¯çµèçæ ¸å¿æ°ï¼åå¤äºä¸ä¼æææï¼è¦èªå·±çä¸çµèçåæ°ï¼æè 填个-j4å°±è¡ï¼æ¯ç«ç°å¨çµè4æ ¸å¿åºè¯¥æ¯æåºæ¬çï¼
- 大æ¦ä»2019å¹´å¼å§çæ°çæ¬çQtCreatoré»è®¤å·²ç»ä¼æ ¹æ®çµèçæ ¸å¿èªå¨è®¾ç½®å¤çº¿ç¨ç¼è¯ï¼æ¯å¦è¯å«å°ä½ ççµèæ¯16æ ¸å¿çå°±ä¼é»è®¤è®¾ç½®-j16åæ°è¿è¡ç¼è¯ï¼
- QtCreator8çæ¬å¼å§ï¼é项é ç½®èåä»å·¥å ·ç§»å°äºç¼è¾èåä¸ï¼å¾å¤äººæç¹ä¸éåºè¯´æä¹æ²¡æäºï¼å ¶å®ç¨å¾®é¼ æ åä¸åæ¾ä¸æ¾å°±çå°äºã
-
å¦æä½ æ³é¡ºå©ç¨QtCreatoré¨ç½²å®åç¨åºï¼é¦å ä½ è¦å¨ Android Studio éé¢é ç½®æåï¼ç¼è¯ä¸ä¸ªç¨åºè½å¤å¨ææºä¸æè 模æå¨ä¸è·èµ·æ¥ï¼æåå ¨é¨è¶å¹³ã
-
å¾å¤æ¶åæ¾å°Qt对åºå°è£ çæ¹æ³åï¼è®°å¾å¤çç该å½æ°çéè½½ï¼å¤ä¸ªåæ°çï¼ä½ ä¼åç°ä¸ä¸æ ·çä¸çï¼ææ¶åä¼æç¶å¤§æï¼åæ¥Qtå·²ç»å¸®æ们å°è£ 好äºï¼æ¯å¦QStringãQColorçéè½½åæ°æå ¶ä¸°å¯ï¼å¾å¤ä½ å梦é½æ³è¦çåè½å°±å¨éé¢ã
-
å¯ä»¥å¨proæ件ä¸åä¸çæ¬å·ãç¨åºå¾æ ã产åå称ãçæææãæ件说æçä¿¡æ¯ï¼Qt5ææ¯æï¼ï¼å ¶å®å¨windowsä¸å°±æ¯qmakeçæ¶åä¼èªå¨å°æ¤ä¿¡æ¯è½¬æ¢ærcæ件ã对äºæ©æçQt4çæ¬ä½ å¯ä»¥æå¨årcæ件å®ç°ã
#ç¨åºçæ¬
VERSION = 2025.10.01
#ç¨åºå¾æ
RC_ICONS = main.ico
#产åå称
QMAKE_TARGET_PRODUCT = quc
#çæææ
QMAKE_TARGET_COPYRIGHT = feiyangqingyun
#æ件说æ
QMAKE_TARGET_DESCRIPTION = QQ: 517216493 WX: feiyangqingyun
- 管çåè¿è¡ç¨åºï¼éå®å¨MSVCç¼è¯å¨ï¼å¨é¡¹ç®proæ件ä¸å¢å å¦ä¸ä»£ç ã
QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'" #以管çåè¿è¡
QMAKE_LFLAGS += /SUBSYSTEM:WINDOWS,"5.01" #VS2013 å¨XPè¿è¡
- è¿è¡æ件é带è°è¯è¾åºçªå£ï¼è¿ä¸ªé常æç¨ï¼å¾å¤æ¶åå½æ们åå¸ç¨åºé¶æ®µï¼æ们ä¼éå°ç¨åºåå»æ æ³è¿è¡ä¹ä¸æ¥éæ示ï¼å¼åæºå¨ä¸ä¸åæ£å¸¸ï¼ï¼é½ä¸ç¥éåçäºä»ä¹ï¼çè³ä»»å¡ç®¡çå¨å¯ä»¥çå°è¿è¡äºä½æ¯æ²¡æçé¢å¼¹åºæ¥ï¼æ¤æ¶å°±éè¦å¨é¡¹ç®çproæ件ä¸å ä¸ä¸è¡CONFIG += consoleï¼å¸¦çé¢çç¨åºä¹ä¼èªå¨å¼¹åºè°è¯çªå£æå°è¾åºä¿¡æ¯ï¼æ¹ä¾¿æ¾é®é¢ï¼ä¸è¬æ²¡æ³æ£å¸¸è¿è¡çç¨åºé½ä¼æå°ä¸äºæ示信æ¯ç¼ºå¥ä¹ç±»çã
TEMPLATE = app
MOC_DIR = temp/moc
RCC_DIR = temp/rcc
UI_DIR = temp/ui
OBJECTS_DIR = temp/obj
#å°±æ¯ä¸é¢è¿è¡ç¨æ¥è®¾ç½®è¿è¡æ件é带è°è¯è¾åºçªå£
CONFIG += console
-
ç»å¶å¹³éºèæ¯QPainter::drawTiledPixmapï¼ç»å¶åè§ç©å½¢QPainter::drawRoundedRect()ï¼èä¸æ¯QPainter::drawRoundRect()ï¼è¿ä¸¤ä¸ªå½æ°é常容æææ··ã
-
æå®æ§ä»¶ç§»é¤æ§çæ ·å¼ã
//移é¤åææ ·å¼
style()->unpolish(ui->btn);
//å¿
é¡»è¦æä¸é¢è¿è¡ä¸ç¶è¿æ¯ä¸ä¼å¸è½½
ui->btn->setStyleSheet("");
//éæ°è®¾ç½®æ°ç该æ§ä»¶çæ ·å¼ã
style()->polish(ui->btn);
02ï¼011-020
- è·åç±»çå±æ§åæ¹æ³
//æ¿å°æ§ä»¶å
对象
const QMetaObject *metaObject = widget->metaObject();
//ææå±æ§çæ°é
int propertyCount = metaObject->propertyCount();
//propertyOffsetæ¯èªå®ä¹çå±æ§å¼å§çä½ç½®
int propertyOffset = metaObject->propertyOffset();
//循ç¯ååºæ§ä»¶çèªå®ä¹å±æ§, int i = 0 表示ææå±æ§
for (int i = propertyOffset; i < propertyCount; ++i) {
QMetaProperty metaProperty = metaObject->property(i);
const char *name = metaProperty.name();
const char *type = metaProperty.typeName();
QVariant value = widget->property(name);
qDebug() << name << type << value;
}
//æææ¹æ³çæ°é
int methodCount = metaObject->methodCount();
//methodOffsetæ¯èªå®ä¹çæ¹æ³å¼å§çä½ç½®
int methodOffset = metaObject->methodOffset();
//循ç¯ååºæ§ä»¶çèªå®ä¹æ¹æ³, int i = 0 表示æææ¹æ³
for (int i = methodOffset; i < methodCount; ++i) {
QMetaMethod metaMethod = metaObject->method(i);
const char *name = metaMethod.name();
const char *type = metaMethod.typeName();
qDebug() << name << type;
}
- Qtå ç½®å¾æ å°è£ å¨QStyleä¸ï¼å¤§æ¦ä¸åå¤ä¸ªå¾æ ï¼å¯ä»¥ç´æ¥æ¿æ¥ç¨ã
SP_TitleBarMenuButton,
SP_TitleBarMinButton,
SP_TitleBarMaxButton,
SP_TitleBarCloseButton,
SP_MessageBoxInformation,
SP_MessageBoxWarning,
SP_MessageBoxCritical,
SP_MessageBoxQuestion,
...
//ä¸é¢è¿æ ·ååºæ¥ä½¿ç¨å°±è¡
QPixmap pixmap = this->style()->standardPixmap(QStyle::SP_TitleBarMenuButton);
ui->label->setPixmap(pixmap);
- æ ¹æ®æä½ç³»ç»ä½æ°å¤æå è½½
win32 {
contains(DEFINES, WIN64) {
DESTDIR = $$PWD/../bin64
} else {
DESTDIR = $$PWD/../bin32
}
}
-
Qt5å¢å¼ºäºå¾å¤å®å ¨æ§éªè¯ï¼å¦æåºç°setGeometry: Unable to set geometryï¼è¯·å°è¯¥æ§ä»¶çå¯è§ç§»å°å å ¥å¸å±ä¹åã
-
å¯ä»¥å°æ§ä»¶Aæ·»å å°å¸å±ï¼ç¶åæ§ä»¶B设置该å¸å±ï¼è¿ç§çµæ´»æ§æé«äºæ§ä»¶çç»å度ï¼æ¯å¦å¯ä»¥å¨ææ¬æ¡å·¦ä¾§å³ä¾§å¢å ä¸ä¸ªæç´¢æé®ï¼æé®è®¾ç½®å¾æ å³å¯ã
QPushButton *btn = new QPushButton;
btn->resize(30, ui->lineEdit->height());
QHBoxLayout *layout = new QHBoxLayout(ui->lineEdit);
layout->setMargin(0);
layout->addStretch();
layout->addWidget(btn);
-
对QLCDNumberæ§ä»¶è®¾ç½®æ ·å¼ï¼éè¦å°QLCDNumberçsegmentstyle设置为flatï¼ä¸ç¶ä½ ä¼åç°æ²¡ææã
-
å·§å¦çä½¿ç¨ findChildren å¯ä»¥æ¥æ¾è¯¥æ§ä»¶ä¸çææåæ§ä»¶ã findChild 为æ¥æ¾å个ã
//æ¥æ¾æå®ç±»åobjectNameçæ§ä»¶
QList<QWidget *> widgets = fatherWidget.findChildren<QWidget *>("widgetname");
//æ¥æ¾ææQPushButton
QList<QPushButton *> allPButtons = fatherWidget.findChildren<QPushButton *>();
//æ¥æ¾ä¸çº§åæ§ä»¶,ä¸ç¶ä¼ä¸ç´éåææåæ§ä»¶
QList<QPushButton *> childButtons = fatherWidget.findChildren<QPushButton *>(QString(), Qt::FindDirectChildrenOnly);
- å·§å¦ç使ç¨inheritså¤ææ¯å¦å±äºæç§ç±»ã
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
-
使ç¨å¼±å±æ§æºå¶ï¼å¯ä»¥åå¨ä¸´æ¶çå¼ç¨äºä¼ éå¤æãå¯ä»¥éè¿widget->dynamicPropertyNames()ååºææå¼±å±æ§å称ï¼ç¶åéè¿widget->property("name")ååºå¯¹åºçå¼±å±æ§çå¼ã
-
å¨å¼åæ¶, æ 论æ¯åºäºç»´æ¤ç便æ·æ§, è¿æ¯èçå åèµæºçèè, é½åºè¯¥æä¸ä¸ª qss æ件æ¥åæ¾ææçæ ·å¼è¡¨, èä¸åºè¯¥å° setStyleSheet åçå°å¤é½æ¯ãå¦ææ¯åå¦é¶æ®µæè æµè¯é¶æ®µå¯ä»¥ç´æ¥UIä¸å³é®è®¾ç½®æ ·å¼è¡¨ï¼æ£å¼é¡¹ç®è¿æ¯å»ºè®®ç»ä¸å°ä¸ä¸ªqssæ ·å¼è¡¨æ件æ¯è¾å¥½ï¼ç»ä¸ç®¡çã
03ï¼021-030
-
å¦æåºç°Z-order assignment: is not a valid widget.é误æ示ï¼ç¨è®°äºæ¬æå¼å¯¹åºçuiæ件ï¼æ¾å°
为空çå°æ¹ï¼å é¤å³å¯ã -
åäºå©ç¨QComboBoxçaddItemç第äºä¸ªåæ°è®¾ç½®ç¨æ·æ°æ®ï¼å¯ä»¥å®ç°å¾å¤ææï¼ä½¿ç¨itemDataååºæ¥ãç¹å«æ³¨æçæ¯ç¬¬äºä¸ªåæ°æ¯QVariantç±»åï¼è¿å°±ä¸è¦å¤ªçµæ´»äºï¼æå³çå¯ä»¥é带ä¸è½çæ°æ®æ¯å¦ç»æä½ï¼è¿æ ·å°±å¯ä»¥å¸¦ä¸å æ°æ®äºï¼èä¸æ¯ä¸ä¸ªæ°æ®ãæ¯å¦ä¸ææ¡éæ©å¦å·ï¼å¯¹åºå ç´ å¯ä»¥é带该å¦ççå§åãç级ãæ绩çãå¾å¤äººä»¥ä¸ºåªè½é带QStringãintä¹ç±»çæ°æ®ï¼å 为é常çç¨æ³ä¹æ¯é£ä¸¤ç§ã
QStringList listVideoOpenInterval, listVideoOpenIntervalx;
listVideoOpenInterval << "0.0 ç§" << "0.1 ç§" << "0.3 ç§" << "0.5 ç§" << "1.0 ç§" << "2.0 ç§";
listVideoOpenIntervalx << "0" << "100" << "300" << "500" << "1000" << "2000";
for (int i = 0; i < listVideoOpenInterval.count(); ++i) {
ui->cboxVideoOpenInterval->addItem(listVideoOpenInterval.at(i), listVideoOpenIntervalx.at(i));
}
//ååºå¯¹åºçå¼
int indexVideoOpenInterval = ui->cboxVideoOpenInterval->currentIndex();
indexVideoOpenInterval = ui->cboxVideoOpenInterval->itemData(indexVideoOpenInterval).toInt();
-
å¦æç¨äºwebengine模åï¼åå¸ç¨åºçæ¶å带ä¸QtWebEngineProcess.exeãtranslationsæ件夹ãresourcesæ件夹ï¼ä¸ç¶æ æ³æ£å¸¸è¿è¡ã
-
å¨MFCç¨åºæè VB/C#ççªä½ç¨åºä¸ï¼æ¯ä¸ªæ§ä»¶é½æä¸ä¸ªå¥æï¼èä¸ç¨å¥æå·¥å ·ç§»è¿å»ä¼èªå¨è¯å«ï¼ä½æ¯å¨Qtç¨åºä¸é»è®¤Qtæ¯ä¸ä¸ªçªä½ä¸ä¸ªå¥æï¼å¦æè¦è®©æ¯ä¸ªæ§ä»¶é½æ¥æç¬ç«çå¥æï¼å¨mainå½æ°ä¸è¦åå¦ä¸è®¾ç½®ã
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setAttribute(Qt::AA_NativeWindows);
}
- Qtç¼åçAndroidç¨åºé²æ¢ç¨åºè¢«å ³éã
#if defined(Q_OS_ANDROID)
QAndroidService a(argc, argv);
return a.exec()
#else
QApplication a(argc, argv);
return a.exec();
#endif
- å¯ä»¥å¯¹æ´ä½çæ示å¨è®¾ç½®æ ·å¼ï¼èä¸éè¦åç¬å¯¹æ¯ä¸ªæ§ä»¶çæ示å¨è®¾ç½®ï¼
*::down-arrow{}
*::menu-indicator{}
*::up-arrow:disabled{}
*::up-arrow:off{}
- å¯ä»¥æå®ä½ç½®è®¾ç½®èæ¯å¾çã
QMainWindow > .QWidget {
background-color: gainsboro;
background-image: url(:/images/xxoo.png);
background-position: top right;
background-repeat: no-repeat
}
- åµå ¥å¼linuxè¿è¡Qtç¨åº
//Qt4åæ³
./HelloQt -qws &
//Qt5åæ³ xcb å¯ä»¥æ¹æ linuxfb eglfs vnc wayland ç,æåªä¸ªå°±ç¨åªä¸ªæ¨ä¸ªæµè¯
./HelloQt --platform xcb
./HelloQt --platform linuxfb
./HelloQt --platform wayland
-
å¦æåç°QtCreatorä¸çæ建å¥ä»¶ä¸æ£å¸¸äºæè åäºï¼æ¯å¦ä¸è½æ£ç¡®è¯å«ç¯å¢ä¸çqmakeæè ç¼è¯å¨ãæå¼é¡¹ç®ä¸è½æ£å¸¸çæå½±åæ建ç®å½ï¼ï¼è¯·æ¾å°ä¸¤ä¸ªç®å½ï¼C:\Users\Administrator\AppData\Local\QtProjectãC:\Users\Administrator\AppData\Roaming\QtProjectï¼å é¤å³å¯ï¼å é¤åéæ°æå¼QtCreatorè¿è¡æ建å¥ä»¶çé 置就è¡ã
-
QMediaPlayeræ¯ä¸ªå£³ï¼ä¹å¯ä»¥å«æ¡æ¶ï¼ï¼ä¾èµæ¬å°è§£ç å¨ï¼è§é¢è¿åé»è®¤åºæ¬ä¸å°±ææ¾ä¸ªMP4çè³è¿MP4é½ä¸è½ææ¾ï¼å¦æè¦æ¯æå ¶ä»æ ¼å¼éè¦ä¸è½½k-liteæè LAV Filterså®è£ å³å¯ï¼k-liteæè LAV Filtersæ¯æwindowsä¸çï¼å ¶ä»ç³»ç»ä¸èªè¡æç´¢ï¼è²ä¼¼åµå ¥å¼linuxä¸ä¾èµGStreamerï¼sudo apt-get install gstreamer1.0-libav ubuntu-restricted-extrasï¼ï¼å¹¶æªå®æ´éªè¯ï¼æ¥éæ示 Your GStreamer installation is missing a plug-inï¼éè¦å½ä»¤å®è£ sudo apt-get install ubuntu-restricted-extrasï¼ãå¦æéè¦ååè½å¼ºå²çææ¾å¨ï¼åå¦è 建议ç¨vlcãmpvï¼ç»æä¸è½å¤§æ³ç¨ffmpegï¼è§£ç åºæ¥çè§é¢å¯ä»¥ç¨QOpenGLWidgetèµ°GPUç»å¶æè 转æQImageç»å¶ï¼é³é¢æ°æ®å¯ä»¥ç¨QAudioOutputææ¾ï¼ã
04ï¼031-040
- å¤æç¼è¯å¨ç±»åãç¼è¯å¨çæ¬ãæä½ç³»ç»ã
//proä¸å¤æç¼è¯å¨çæ¬
greaterThan(MSC_VER, 1900) {
}
//GCCç¼è¯å¨
#ifdef __GNUC__
#if __GNUC__ >= 3 // GCC3.0 以ä¸
//MSVCç¼è¯å¨
#ifdef _MSC_VER
#if _MSC_VER >=1000 // VC++4.0 以ä¸
#if _MSC_VER >=1100 // VC++5.0 以ä¸
#if _MSC_VER >=1200 // VC++6.0 以ä¸
#if _MSC_VER >=1300 // VC2003 以ä¸
#if _MSC_VER >=1400 // VC2005 以ä¸
#if _MSC_VER >=1500 // VC2008 以ä¸
#if _MSC_VER >=1600 // VC2010 以ä¸
#if _MSC_VER >=1700 // VC2012 以ä¸
#if _MSC_VER >=1800 // VC2013 以ä¸
#if _MSC_VER >=1900 // VC2015 以ä¸
//Visual Studioçæ¬ä¸MSVCçæ¬å·ç对åºå
³ç³»
MSC 1.0 _MSC_VER == 100
MSC 2.0 _MSC_VER == 200
MSC 3.0 _MSC_VER == 300
MSC 4.0 _MSC_VER == 400
MSC 5.0 _MSC_VER == 500
MSC 6.0 _MSC_VER == 600
MSC 7.0 _MSC_VER == 700
MSVC++ 1.0 _MSC_VER == 800
MSVC++ 2.0 _MSC_VER == 900
MSVC++ 4.0 _MSC_VER == 1000 (Developer Studio 4.0)
MSVC++ 4.2 _MSC_VER == 1020 (Developer Studio 4.2)
MSVC++ 5.0 _MSC_VER == 1100 (Visual Studio 97 version 5.0)
MSVC++ 6.0 _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
MSVC++ 7.0 _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005 version 8.0)
MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008 version 9.0)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010 version 10.0)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012 version 11.0)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013 version 12.0)
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 Version 16.1)
MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 Version 16.2)
MSVC++ 14.30 _MSC_VER == 1930 (Visual Studio 2022 Version 17.0)
MSVC++ 14.31 _MSC_VER == 1931 (Visual Studio 2022 Version 17.1)
MSVC++ 14.32 _MSC_VER == 1932 (Visual Studio 2022 Version 17.2)
//Borland C++
#ifdef __BORLANDC__
//Cygwin
#ifdef __CYGWIN__
#ifdef __CYGWIN32__
//mingw
#ifdef __MINGW32__
//windows
#ifdef _WIN32 //32bit
#ifdef _WIN64 //64bit
#ifdef _WINDOWS //å¾å½¢çé¢ç¨åº
#ifdef _CONSOLE //æ§å¶å°ç¨åº
//Windowsï¼95/98/Me/NT/2000/XP/Vistaï¼åWindows CEé½å®ä¹äº
#if (WINVER >= 0x030a) // Windows 3.1以ä¸
#if (WINVER >= 0x0400) // Windows 95/NT4.0以ä¸
#if (WINVER >= 0x0410) // Windows 98以ä¸
#if (WINVER >= 0x0500) // Windows Me/2000以ä¸
#if (WINVER >= 0x0501) // Windows XP以ä¸
#if (WINVER >= 0x0600) // Windows Vista以ä¸
//_WIN32_WINNT å
æ ¸çæ¬
#if (_WIN32_WINNT >= 0x0500) // Windows 2000以ä¸
#if (_WIN32_WINNT >= 0x0501) // Windows XP以ä¸
#if (_WIN32_WINNT >= 0x0600) // Windows Vista以ä¸
- å¨proä¸å¤æQtçæ¬åæ建å¥ä»¶ä½æ°
#æå°çæ¬ä¿¡æ¯
message(qt version: $$QT_VERSION)
#å¤æå½åqtçæ¬å·
QT_VERSION = $$[QT_VERSION]
QT_VERSION = $$split(QT_VERSION, ".")
QT_VER_MAJ = $$member(QT_VERSION, 0)
QT_VER_MIN = $$member(QT_VERSION, 1)
#ä¸é¢æ¯è¡¨ç¤º Qt5.5å以ä¸çæ¬
greaterThan(QT_VER_MAJ, 4) {
greaterThan(QT_VER_MIN, 4) {
#èªå·±æ ¹æ®éè¦åä¸äºå¤ç
}}
#QT_ARCHæ¯Qt5æ°å¢ç,å¨Qt4ä¸æ²¡ææ
#æå°å½åQtæ建å¥ä»¶çä¿¡æ¯
message($$QT_ARCH)
#表示armå¹³å°æ建å¥ä»¶
contains(QT_ARCH, arm) {}
#表示32ä½çæ建å¥ä»¶
contains(QT_ARCH, i386) {}
#表示64ä½çæ建å¥ä»¶
contains(QT_ARCH, x86_64) {}
#å
¶å®Qtå
ç½®äºä¸»çæ¬å·ååçæ¬å·åé
#å¤æå½åqtçæ¬å·
message($$QT_ARCH : $$QT_VERSION -> $$QT_MAJOR_VERSION . $$QT_MINOR_VERSION)
#ä¸é¢çå«ä¹æ¯å¦æçæ¬ < 4.8
lessThan(QT_MAJOR_VERSION, 5) {
lessThan(QT_MINOR_VERSION, 8) {
#è¿éæ¾è¦åçå¤ç
}}
#ä¸é¢çå«ä¹æ¯å¦æçæ¬ < 5.12.0
REQ_QT_MAJOR = 5
REQ_QT_MINOR = 12
REQ_QT_PATCH = 0
lessThan(QT_MAJOR_VERSION, $$REQ_QT_MAJOR)|lessThan(QT_MINOR_VERSION, $$REQ_QT_MINOR)|lessThan(QT_MINOR_VERSION, $$REQ_QT_PATCH) {
#è¿éæ¾è¦åçå¤ç
}
#ä¸é¢çå«ä¹æ¯å¦æçæ¬ >= 5.5
greaterThan(QT_MAJOR_VERSION, 4) {
greaterThan(QT_MINOR_VERSION, 4) {
#è¿éæ¾è¦åçå¤ç
}}
//代ç ä¸å¤æçæ¬ä¸è¦å¤ªç®å
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
//è¿éæ¾è¦åçå¤ç
#endif
//ä¸é¢è¡¨ç¤º >= 5.0.0
#if QT_VERSION >= 0x050000
...
#endif
//ä¸é¢è¡¨ç¤º < 5.12.10
#if QT_VERSION < 0x050C0A
...
#endif
- Qtæå°ååæ¢å¤çé¢å¯è½ä¼åºç°åæ»å»ç»ç°è±¡ï¼å ä¸ä»£ç
void showEvent(QShowEvent *e)
{
setAttribute(Qt::WA_Mapped);
QWidget::showEvent(e);
}
-
è·åæ é¢æ é«åº¦ï¼style()->pixelMetric(QStyle::PM_TitleBarHeight); PM_TitleBarHeightç¹è¿å»ä½ ä¼åç°æ°å¤§éï¼æä¸å ç©æå¨éé¢ã
-
设置é«åå±å±æ§ä»¥ä¾¿æ¯æ2K4Kçé«å辨çï¼å°¤å ¶æ¯ææºappãå¿ é¡»åå¨mainå½æ°çQApplication a(argc, argv);çåé¢ã
#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0))
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication a(argc, argv);
- å¦æè¿è¡ç¨åºåºç° Fault tolerant heap shim applied to current process. This is usually due to previous crashes. é误ã
- 第ä¸æ¥ï¼è¾å ¥å½ä»¤ regedit æå¼æ³¨å表ï¼
- 第äºæ¥ï¼æ¾å°èç¹ HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\ï¼
- 第ä¸æ¥ï¼éä¸Layersé®å¼ï¼ä»å³ä¾§å表ä¸å é¤èªå·±çé£ä¸ªç¨åºè·¯å¾å³å¯ã
-
Qtå ç½®äºQFormLayout表åå¸å±ç¨äºèªå¨çææ ç¾+è¾å ¥æ¡çç»åç表åçé¢ï¼è®¾ç½®å¸å±ç¨çå¾å°ï¼ä¸è¬ç¨çæå¤çæ¯æ¨ªåå¸å±ãåç´å¸å±ãè¡¨æ ¼å¸å±ã
-
qmlææ¾è§é¢å¨linuxéè¦å®è£ sudo apt-get install libpulse-devã
-
å¯ä»¥ç´æ¥ç»§æ¿QSqlQueryModelå®ç°èªå®ä¹çQueryModelï¼æ¯å¦æä¸ååä½é¢è²ï¼å ä½ç¬¦ï¼å ¶ä»æ ·å¼çï¼éåQVariant CustomSqlModel::data(const QModelIndex &index, int role) constã
-
Qt5以åæä¾äºç±»QScrollerç´æ¥å°æ§ä»¶æ»å¨ã
//ç¦ç¨æ¨ªåæ»å¨æ¡
ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//ç¦ç¨çºµåæ»å¨æ¡
ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//设置横åæç
§åç´ å¼ä¸ºåä½æ»å¨
ui->listWidget->setHorizontalScrollMode(QListWidget::ScrollPerPixel);
//设置纵åæç
§åç´ å¼ä¸ºåä½æ»å¨
ui->listWidget->setVerticalScrollMode(QListWidget::ScrollPerPixel);
//设置æ»å¨å¯¹è±¡ä»¥åæ»å¨æ¹å¼ä¸ºé¼ æ å·¦é®æå¨æ»å¨
QScroller::grabGesture(ui->listWidget, QScroller::LeftMouseButtonGesture);
//è¿æ个QScrollerPropertieså¯ä»¥è®¾ç½®æ»å¨çä¸äºåæ°
05ï¼041-050
- å¦æ使ç¨sqliteæ°æ®åºä¸æ³äº§çæ°æ®åºæ件ï¼å¯ä»¥å建å åæ°æ®åºã
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
-
æ¸ ç©ºæ°æ®è¡¨å¹¶éç½®èªå¢IDï¼sql = truncate table table_nameã
-
QtChart模åä»Qt5.7å¼å§èªå¸¦ï¼æä½ç¼è¯è¦æ±Qt5.4ãå¨å®è£ çæ¶åè®°å¾å¾éï¼é»è®¤ä¸å¾éã使ç¨è¯¥æ¨¡åéè¦å¼å ¥å½å空é´ã
#include <QChartView>
QT_CHARTS_USE_NAMESPACE
class CustomChart : public QChartView
-
QPushButton左对é½æåï¼éè¦è®¾ç½®æ ·å¼è¡¨QPushButton{text-align:left;}
-
QLabelæä¸ç§è®¾ç½®ææ¬çæ¹æ³ï¼ææ¡å¥½Qtçå±æ§ç³»ç»ï¼ä¸¾ä¸åä¸ï¼å¯ä»¥ååºå¾å¤ææã
//常è§åæ³
ui->label->setText("hello");
//åå·§åæ³
ui->label->setProperty("text", "hello");
//å±æ§å¤§æ³
ui->label->setStyleSheet("qproperty-text:hello;");
- å·§å¦çç¨QEventLoopå¼å¯äºä»¶å¾ªç¯ï¼å¯ä»¥ä½¿å¾å¾å¤åæ¥è·åè¿åç»æèä¸é»å¡çé¢ãæ¥çæºç å¾ç¥ï¼åæ¥QEventLoopå é¨æ°å»ºäºçº¿ç¨æ§è¡ã
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
- Qtä¸ä¹æ¯æå¤ç§é¢å®ä¹åéç»åå¤æï¼å»æçæ空çdebugåreleaseç®å½ï¼å¨proæ件ä¸å ä¸è¡ CONFIG -= debug_and_releaseã
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#endif
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#endif
#ifdef Q_OS_WIN
//windowsç³»ç»
#else
//éwindowsç³»ç»
#endif
//ä¸é¢åæ³ç¼è¯ä¼æ¥é
#ifdef Q_OS_WIN
#elif Q_OS_LINUX
#endif
//æ£ç¡®åæ³
#if defined(Q_OS_WIN)
#elif defined(Q_OS_LINUX)
#endif
-
æ°ççQtcreatorå¢å¼ºäºè¯æ³æ£æ¥ï¼ä¼å¼¹åºå¾å¤è¦åæ示çï¼å¯ä»¥å¨æ件å表ä¸å ³éclangæ头çå 个å³å¯ï¼HelpãAbout Pluginsãä¹å¯ä»¥è®¾ç½®ä»£ç æ£æ¥çº§å«ï¼ToolsãOptions ãC++ ãCode Modelã
-
QSqlTableModelçrowCountæ¹æ³ï¼é»è®¤æ大è¿å256ï¼å¦æè¶ è¿256ï¼å¯ä»¥å°è¡¨æ ¼æå°åºé¨ï¼ä¼èªå¨å è½½å©ä½çï¼æ¯æ¬¡æ大å è½½256æ¡æ°æ®ï¼å¦æéè¦æå°æè 导åºæ°æ®ï¼è®°å¾æ好éç¨sqlè¯å¥å»æ¥è¯¢ï¼èä¸æ¯ä½¿ç¨QSqlTableModelçrowCountæ¹æ³ãä¸ç¶æ°¸è¿æ大åªä¼å¯¼åº256æ¡æ°æ®ã å¦ææ°æ®éå¾å°ï¼ä¹å¯ä»¥éç¨å¦ä¸æ¹æ³ï¼
//主å¨å è½½æææ°æ®,ä¸ç¶è·åå°çè¡æ°<=256
while(model->canFetchMore()) {
model->fetchMore();
}
- å¦æéè¦æå®æ è¾¹æ¡çªä½ï¼ä½æ¯åéè¦ä¿çæä½ç³»ç»çè¾¹æ¡ç¹æ§ï¼æ¯å¦èªç±æ伸边æ¡ï¼å¯ä»¥ä½¿ç¨ setWindowFlags(Qt::CustomizeWindowHint)ï¼è¿æ ·ä¼ä¿çä¸ä¸ªç³»ç»ç½è¾¹æ¡ã
06ï¼051-060
- å¨æäºhttp postæ°æ®çæ¶åï¼å¦æéç¨çæ¯&å符串è¿æ¥çæ°æ®åéï¼ä¸æ解æä¹±ç çè¯ï¼éè¦å°ä¸æè¿è¡URL转ç ã
QString content = "æµè¯ä¸æ";
QString note = content.toUtf8().toPercentEncoding();
-
Qté»è®¤ä¸æ¯æ大èµæºæ件ï¼æ¯å¦æ·»å äºåä½æ件ï¼éè¦proæ件å¼å¯ã CONFIG += resources_big
-
Qtä¸ç»§æ¿QWidgetä¹åï¼æ ·å¼è¡¨ä¸èµ·ä½ç¨ï¼è§£å³åæ³æä¸ä¸ªã强çæ¨èæ¹æ³ä¸ã
- æ¹æ³ä¸ï¼è®¾ç½®å±æ§ this->setAttribute(Qt::WA_StyledBackground, true);
- æ¹æ³äºï¼æ¹æ继æ¿QFrameï¼å 为QFrameèªå¸¦paintEventå½æ°å·²åäºå®ç°ï¼å¨ä½¿ç¨æ ·å¼è¡¨æ¶ä¼è¿è¡è§£æåç»å¶ã
- æ¹æ³ä¸ï¼éæ°å®ç°QWidgetçpaintEventå½æ°æ¶ï¼ä½¿ç¨QStylePainterç»å¶ã
void Widget::paintEvent(QPaintEvent *)
{
QStyleOption option;
option.initFrom(this);
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
}
-
ææ¶åå¨çé¢ä¸å äºå¼¹ç°§ï¼éè¦å¨ææ¹å弹簧对åºçæ伸çç¥ï¼å¯¹åºæ¹æ³ä¸ºchangeSizeï¼å¾å¤äººä¼éæ©ä½¿ç¨setå¼å¤´å»æ¾ï¼æ¾ä¸å°çã
-
å¨ä½¿ç¨QFileçè¿ç¨ä¸ï¼ä¸å»ºè®®é¢ç¹çæå¼æ件åå ¥ç¶ååå ³éæ件ï¼æ¯å¦é´é5msè¾åºæ¥å¿ï¼IOæ§è½ç¶é¢å¾å¤§ï¼è¿ç§æ åµå»ºè®®å æå¼æ件ä¸è¦å ³éï¼çå¾ åéçæ¶æºæ¯å¦ææå½æ°ä¸æè æ¥æåäºéè¦éæ°åæ¢æ¥å¿æ件çæ¶åå ³éæ件ãä¸ç¶çæ¶é´å 大éçæå¼å ³éæ件ä¼å¾å¡ï¼æ件è¶å¤§è¶å¡ã
-
å¨å¾å¤ç½ç»åºç¨ç¨åºï¼éè¦èªå®ä¹å¿è·³å æ¥ä¿æè¿æ¥ï¼ä¸ç¶æçµæè éæ³å ³éç¨åºï¼å¯¹æ¹ä¸è½ç«å³è¯å«æè è¦å¾ä¹ ï¼ä¸è¬è³å°è¦30sï¼æè½è¯å«å°ï¼éè¦è¿è¡è¶ æ¶æ£æµï¼ä½æ¯æäºç¨åºæ²¡ææä¾å¿è·³åè®®ï¼æ¤æ¶éè¦å¯ç¨ç³»ç»å±çä¿æ´»ç¨åºï¼æ¤æ¹æ³éç¨äºTCPè¿æ¥ã
int fd = tcpSocket->socketDescriptor();
int keepAlive = 1; //å¼å¯keepaliveå±æ§,缺çå¼:0(å
³é)
int keepIdle = 5; //å¦æå¨5ç§å
没æä»»ä½æ°æ®äº¤äº,åè¿è¡æ¢æµ,缺çå¼:7200(s)
int keepInterval = 2; //æ¢æµæ¶åæ¢æµå
çæ¶é´é´é为2ç§,缺çå¼:75(s)
int keepCount = 2; //æ¢æµéè¯ç次æ°,å
¨é¨è¶
æ¶å认å®è¿æ¥å¤±æ,缺çå¼:9(次)
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepAlive, sizeof(keepAlive));
setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, (void *)&keepIdle, sizeof(keepIdle));
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, (void *)&keepInterval, sizeof(keepInterval));
setsockopt(fd, SOL_TCP, TCP_KEEPCNT, (void *)&keepCount, sizeof(keepCount));
-
å¦æç¨åºæå 好以åå¼¹åºæ示 This application failed to start because it could not find or load the Qt platform plugin ä¸è¬é½æ¯å 为platformsæ件ç®å½æªæå æè æå éäºçåå 导è´çã
-
é常ä¸å»ºè®®trä¸å å«ä¸æï¼å°½ç®¡ç°å¨çæ°çQtæ¯æä¸æå°å ¶ä»è¯è¨çç¿»è¯ï¼ä½æ¯å¾ä¸è§èï¼ä¹ä¸ç¥éTMDæ¯è°æçï¼åé¢åç°æå¨åå¦Qtçæ¶åä¹åå¸äºä¸äºdemoå°ç½ä¸ä¹æ¯trå å«ä¸æçï¼å½æ¶å°±ç ç çæäºèªå·±ä¸å·´æï¼ï¼trçæ¬ææ¯å å«è±æï¼ç¶åç¿»è¯å°å ¶ä»è¯è¨æ¯å¦ä¸æï¼ç°å¨å¤§éçåå¦è 滥ç¨trï¼å¦æ没æç¿»è¯çéæ±ï¼ç¦ç¨trï¼tréè¦å¼éçï¼Qté»è®¤ä¼è®¤ä¸ºä»éè¦ç¿»è¯ï¼ä¼é¢å¤è¿è¡ç¹æ®å¤çã
-
å ³äºQtåQt Creatorçåºå«
- å¾å¤äººQtåQt Creatorå»å»åä¸æ¸ æ¥ï¼ç»å¸¸é®çä¸Qtä»ä¹çæ¬ï¼ç»æåä¸ä¸ªQt Creatorççæ¬è¿æ¥ã
- Qt Creatoræ¯ä½¿ç¨Qtç¼åçéæå¼åç¯å¢IDEï¼åå®å®ç¬¬ä¸çVisual Studioä¸æ ·ã
- ä»å¯ä»¥æ¯msvcç¼è¯å¨çï¼windows对åºçQtéæå®è£ ç¯å¢ä¸èªå¸¦çQt Ceratoræ¯msvcçï¼ï¼ä¹å¯ä»¥æ¯mingwç¼è¯çï¼è¿å¯ä»¥æ¯gccçã
- å¦ææ¯èªå®ä¹æ§ä»¶æ件ï¼éè¦éæå°Qt Creatorä¸ï¼å¿ é¡»ä¿è¯è¯¥æ件çå¨æåºæ件ï¼dllæè soçæ件ï¼å¯¹åºçç¼è¯å¨åQtçæ¬ä»¥åä½æ°åQt Creatorççæ¬å®å ¨ä¸è´æè¡ï¼å¦ååºæ¬ä¸å¤§å¯è½éæè¿å»ã
- ç¹å«æ³¨æçæ¯Qtéæç¯å¢å®è£ å ä¸çQtçæ¬åQt Creatorçæ¬æªå¿ å®å ¨ä¸è´ï¼å¿ é¡»æ¦äº®ç¼ççæ¸ æ¥ï¼æäºæ¯å®å ¨ä¸è´çã
- ç±äºæ°ççQtè¦æ±å¨çº¿å®è£ ï¼èä¸å¨çº¿å®è£ éæ©å¨ä¸Qt Creatorççæ¬æ æ³éæ©ï¼æ°ççQt Creatorç¨çæ¯Qt6ç¼è¯çï¼æ以就åºç°äºwin7ç³»ç»ä¸æ¯æçæ åµã
- æ¨èç¨win10æè win11ç³»ç»åå¼åç¯å¢ã
- ä½ å¯ä»¥å¨é«çæ¬çQt Creatorä¸åå¼åï¼éæ©æ¯æwin7çå¥ä»¶çæ¬æ¯å¦5.15æè éæ©æ¯æxpçå¥ä»¶çæ¬5.6å³å¯ï¼åå¸åä¾ç¶å¯ä»¥æ£å¸¸å¨ä½çæ¬çç³»ç»è¿è¡ã
- è¶ è¿ä¸¤å¤ç¸åå¤çç代ç ï¼å»ºè®®åç¬åæå½æ°ã代ç å°½éè§èç²¾ç®ï¼æ¯å¦ if(a == 123) è¦åæ if (123 == a)ï¼å¼å¨åé¢ï¼åæ¯å¦ if (ok == true) è¦åæ if (ok)ï¼if (ok == false) è¦åæ if (!ok)çã
07ï¼061-070
-
å¾å¤äººé®Qtåµå ¥å¼å¹³å°ç¨åªä¸ªå¥½ï¼è¿éç»ä¸åçï¼å½åæ¶é´èç¹2018å¹´ï¼ï¼imx6+335xæ¯è¾ç¨³å®ï¼æ§è½é«å°±ç¨RK3288 RK3399ï¼ä¾¿å®çè¯å°±ç¨å ¨å¿H3ï¼ç©ä¸ç©å¯ä»¥ç¨æ èæ´¾é¦æ©æ´¾ã
-
对äºå¤§æ®µç注é代ç ï¼å»ºè®®ç¨ #if 0 #endif å°ä»£ç åå å«èµ·æ¥ï¼èä¸æ¯å°è¯¥æ®µä»£ç éä¸ç¶åå ¨é¨åææ 注éï¼ä¸æ¬¡è¦æå¼è¿æ®µä»£ç çè¯ï¼åéè¦éæ°éä¸ä¸æ¬¡åæ¶ï¼å¦æéç¨çæ¯ #if 0ååªè¦æ0æ¹æ1å³å¯ï¼å¼åæçæåå¾å¤ã
-
Qtæå åå¸ï¼æå¾å¤åæ³ï¼Qt5以åæä¾äºæå å·¥å ·windeployqtï¼linuxä¸ä¸ºlinuxdeployqtï¼macä¸ä¸ºmacdeployqtï¼å¯ä»¥å¾æ¹ä¾¿çå°åºç¨ç¨åºæå ï¼ä½¿ç¨ä¸æ¥åç°ä¹ä¸æ¯ä¸è½çï¼ææ¶åä¼å¤æå ä¸äºæ²¡æä¾èµçæ件ï¼ææ¶ååä¼å¿è®°æå ä¸äºæä»¶å°¤å ¶æ¯ç¨äºqmlçæ åµä¸ï¼èä¸ä¸è½è¯å«ç¬¬ä¸æ¹åºï¼æ¯å¦ç¨åºä¾èµffmpegï¼å对åºçåºéè¦èªè¡æ·è´ï¼ç»æ大æ³å°±æ¯å°ä½ çå¯æ§è¡æ件å¤å¶å°Qtå®è£ ç®å½ä¸çbinç®å½ï¼ç¶åæ´ä¸ªä¸èµ·æå ï¼æ¨ä¸ªå é¤ä¸å¤§å¯è½ä¾èµçç»ä»¶ï¼ç´å°å å°æ£å¸¸è¿è¡ä¸ºæ¢ã
-
Qtä¸çå¨ç»ï¼åºå±ç¨çæ¯QElapsedTimerå®æ¶å¨æ¥å®æå¤çï¼æ¯å¦äº§çä¸äºæå®è§åç®æ³çæ°æ®ï¼ç¶å对å±æ§è¿è¡å¤çã
-
å¨ç»å¶æ èæ¯é¢è²åªæè¾¹æ¡é¢è²çåå½¢æ¶åï¼å¯ä»¥ç¨ç»å¶360度çå弧æ¿ä»£ï¼ææå®å ¨ä¸è´ã
QRect rect(-radius, -radius, radius * 2, radius * 2);
//以ä¸ä¸¤ç§æ¹æ³äºéä¸,å
¶å®ç»å¶360度çå弧=ç»å¶æ èæ¯çåå½¢
painter->drawArc(rect, 0, 360 * 16);
painter->drawEllipse(rect);
-
ä¸è¦ædæéççå¾çä¹ï¼å ¶å®å°±æ¯å¨ç±»çå®ç°æ件å®ä¹äºä¸ä¸ªç§æç±»ï¼ç¨æ¥åæ¾å±é¨åéï¼ä¸ªäººå»ºè®®å¨åä¸äºå°é¡¹ç®æ¶ï¼æ²¡æå¤ªå¤§å¿ è¦å¼å ¥è¿ç§æºå¶ï¼ä¼éä½ä»£ç å¯è¯»æ§ï¼å¢å å¤ææ§ï¼æ°ææ¥å项ç®åä¼ççå¾æµé¼ã
-
å¾å¤äººå¨ç»å¶çæ¶åï¼è®¾ç½®ç»ç¬ä»¥ä¸ºå°±åªå¯ä»¥è®¾ç½®ä¸ªåè°çé¢è²ï¼å ¶å®QPenè¿å¯ä»¥è®¾ç½®brushï¼è¿æ ·çµæ´»æ§å°±æé«ä¸ç¥éå¤å°åï¼æ¯å¦è®¾ç½®QPençbrush以åï¼å¯ä»¥ä½¿ç¨åç§æ¸åï¼æ¯å¦ç»å¶æ¸åé¢è²çè¿åº¦æ¡åæåçï¼èä¸åæ¯åè°çä¸ç§é¢è²ã
-
å¾å¤æ§ä»¶é½å¸¦æviewportï¼æ¯å¦QTextEdit/QTableWidget/QScrollAreaï¼ææ¶å对è¿äºæ§ä»¶ç´æ¥å¤ççæ¶ååç°ä¸èµ·ä½ç¨ï¼éè¦å¯¹å ¶viewport()设置æè¡ï¼æ¯å¦è®¾ç½®æ»å¨æ¡åºåèæ¯éæï¼éè¦ä½¿ç¨scrollArea->viewport()->setStyleSheet("background-color:transparent;");èä¸æ¯scrollArea->setStyleSheet("QScrollArea{background-color:transparent;}");
-
ææ¶å设置äºé¼ æ è·è¸ªsetMouseTracking为çï¼å¦æ该çªä½ä¸é¢è¿æå ¶ä»æ§ä»¶ï¼å½é¼ æ 移å°å ¶ä»æ§ä»¶ä¸é¢çæ¶åï¼ç¶ç±»çé¼ æ 移å¨äºä»¶MouseMoveè¯å«ä¸å°äºï¼æ¤æ¶éè¦ç¨å°HoverMoveäºä»¶ï¼éè¦å 设置 setAttribute(Qt::WA_Hover, true);
-
Qtå°è£ çQDateTimeæ¥ææ¶é´ç±»é常强大ï¼å¯ä»¥å符串åæ¥ææ¶é´ç¸äºè½¬æ¢ï¼ä¹å¯ä»¥æ¯«ç§æ°åæ¥ææ¶é´ç¸äºè½¬æ¢ï¼è¿å¯ä»¥1970ç»è¿çç§æ°åæ¥ææ¶é´ç¸äºè½¬æ¢çã
QDateTime dateTime;
QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
//ä»å符串转æ¢ä¸ºæ¯«ç§ï¼éå®æ´çå¹´ææ¥æ¶åç§ï¼
datetime.fromString("2011-09-10 12:07:50:541", "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
//ä»å符串转æ¢ä¸ºç§ï¼éå®æ´çå¹´ææ¥æ¶åç§ï¼
datetime.fromString("2011-09-10 12:07:50:541", "yyyy-MM-dd hh:mm:ss:zzz").toTime_t();
//ä»æ¯«ç§è½¬æ¢å°å¹´ææ¥æ¶åç§
datetime.fromMSecsSinceEpoch(1315193829218).toString("yyyy-MM-dd hh:mm:ss:zzz");
//ä»ç§è½¬æ¢å°å¹´ææ¥æ¶åç§ï¼è¥æzzzï¼å为000ï¼
datetime.fromTime_t(1315193829).toString("yyyy-MM-dd hh:mm:ss[:zzz]");
08ï¼071-080
-
å¨æ们使ç¨QListãQStringListãQByteArrayçé¾è¡¨æè æ°ç»çè¿ç¨ä¸ï¼å¦æåªéè¦åå¼ï¼èä¸æ¯èµå¼ï¼å¼ºçå»ºè®®ä½¿ç¨ at() åå¼èä¸æ¯ [] æä½ç¬¦ï¼å¨å®æ¹ä¹¦ç±ãC++ GUI Qt 4ç¼ç¨ï¼ç¬¬äºçï¼ãç书ä¸æç¹å«ç强è°è¯´æï¼æ¤ææçåä½è æ®è¯´æ¯Qtå¼åçæ ¸å¿äººåç¼åçï¼æ以è¿æ¯æ¯è¾æå¨ï¼è³äºä½¿ç¨ at() ä¸ä½¿ç¨ [] æä½ç¬¦é度æççæ¯è¾ï¼ç½ä¸ä¹æç½ååè¿æ¤ç±»å¯¹æ¯ãåæå¨ä¹¦ç212页ï¼è¿æ ·æè¿°çï¼Qt对ææç容å¨å许å¤å ¶ä»ç±»é½ä½¿ç¨éå«å ±äº«ï¼éå«å ±äº«æ¯Qt对ä¸å¸æä¿®æ¹çæ°æ®å³ä¸è¿è¡å¤å¶çä¿è¯ï¼ä¸ºäºä½¿éå«å ±äº«çä½ç¨åæ¥å¾æ好ï¼å¯ä»¥éç¨ä¸¤ä¸ªæ°çç¼ç¨ä¹ æ¯ã第ä¸ç§ä¹ æ¯æ¯å¯¹äºä¸ä¸ªï¼é常éçï¼åéæè å表è¿è¡åªè¯»ååæ¶ï¼ä½¿ç¨ at() å½æ°èä¸ç¨ [] æä½ç¬¦ï¼å 为Qtç容å¨ç±»ä¸è½è¾¨å« [] æä½ç¬¦æ¯å¦å°åºç°å¨ä¸ä¸ªèµå¼ç左边è¿æ¯å³è¾¹ï¼ä»å设æåçæ åµåºç°å¹¶ä¸å¼ºå¶æ§è¡æ·±å±èµå¼ï¼è at() å½æ°åä¸è¢«å 许åºç°å¨ä¸ä¸ªèµå¼ç左边ã
-
å¦ææ¯dialogçªä½ï¼éè¦å¨exec以åè¿è½è®©å ¶ä»ä»£ç 继ç»æ§è¡ï¼è¯·å¨dialogçªä½execåå¢å ä¸è¡ä»£ç ï¼å¦åä¼é»å¡çªä½æ¶æ¯ã
QDialog dialog;
dialog.setWindowModality(Qt::WindowModal);
dialog.exec();
-
å®å ¨çå é¤Qtç对象类ï¼å¼ºç建议使ç¨deleteLaterèä¸æ¯deleteï¼å 为deleteLaterä¼éæ©å¨åéçæ¶æºè¿è¡éæ¾ï¼èdeleteä¼ç«å³éæ¾ï¼å¾å¯è½ä¼åºéå´©æºãå¦æè¦æ¹éå é¤å¯¹è±¡éåï¼å¯ä»¥ç¨qDeleteAllï¼æ¯å¦ qDeleteAll(btns);
-
å¨QTableViewæ§ä»¶ä¸ï¼å¦æéè¦èªå®ä¹çåæé®ãå¤éæ¡ãä¸ææ¡çå ¶ä»æ¨¡å¼æ¾ç¤ºï¼å¯ä»¥éç¨èªå®ä¹å§æQItemDelegateæ¥å®ç°ï¼å¦æéè¦ç¦ç¨æåï¼åå¨èªå®ä¹å§æçéè½½createEditorå½æ°è¿å0å³å¯ãèªå®ä¹å§æ对åºçæ§ä»¶å¨è¿å ¥ç¼è¾ç¶æçæ¶ååºç°ï¼å¦ææ³ä¸ç´åºç°ï¼åéè¦éè½½paintå½æ°ç¨drawPrimitiveæè drawControlæ¥ç»å¶ã
-
å° QApplication::style() 对åºçdrawPrimitiveãdrawControlãdrawItemTextãdrawItemPixmapçå 个æ¹æ³ç¨çæäºï¼åç»åQStyleOptionå±æ§ï¼å¯ä»¥ç©è½¬åç§èªå®ä¹å§æï¼è¿å¯ä»¥ç´æ¥ä½¿ç¨paintå½æ°ä¸çpainterè¿è¡åç§ç»å¶ï¼åç§çé¼çè¡¨æ ¼ãæ ç¶å表ãä¸ææ¡çï¼ç»å¯¹å±ç¸å¤©ãQApplication::style()->drawControl ç第4个åæ°å¦æä¸è®¾ç½®ï¼åç»å¶åºæ¥çæ§ä»¶ä¸ä¼åºç¨æ ·å¼è¡¨ã
-
å¿ä¸æåæ ï¼ä¸ç©çpainterï¼å¼ºç建议å¨å¦ä¹ èªå®ä¹æ§ä»¶ç»å¶çæ¶åï¼å°qpainter.h头æ件ä¸çå½æ°å ¨é¨çä¸éãè¯ä¸éãç解ä¸éï¼è¿éè¾¹å å«äºææQtå ç½®çç»å¶çæ¥å£ï¼å¯¹åºçåæ°é½è¯ä¸éï¼ä½ ä¼åç°å¾å¤æ°å¤§éï¼ä¼ä¸å®ç¨åº¦ä¸æ¿åä½ çç»å¶çå ´è¶£ï¼ç¹å¦ç¥ç¬é©¬è¯ä¸è¬ï¼çé©¬å´©è ¾é¨æ¸¸ä»£ç ç»å¶çä¸çã
-
å¨ä½¿ç¨setItemWidgetæè setCellWidgetçè¿ç¨ä¸ï¼ææ¶åä¼åç°è®¾ç½®çæ§ä»¶æ²¡æå± ä¸æ¾ç¤ºèæ¯é»è®¤ç左对é½ï¼èä¸ä¸ä¼èªå¨æ伸填å ï¼å¯¹äºè¿½æ±å®ç¾çç¨åºåæ¥è¯´ï¼è¿ä¸ªå¯ä¸å¤§å¥½çï¼æ个ç»æéç¨åæ³å°±æ¯ï¼å°è¿ä¸ªæ§ä»¶æ¾å°ä¸ä¸ªwidgetçå¸å±ä¸ï¼ç¶åå°widgetæ·»å å°itemä¸ï¼è¿æ ·å°±å®ç¾è§£å³äºï¼èä¸è¿æ ·å¯ä»¥ç»åå¤ä¸ªæ§ä»¶äº§çå¤æçæ§ä»¶ã
//å®ä¾åè¿åº¦æ¡æ§ä»¶
QProgressBar *progress = new QProgressBar;
//å¢å widget+å¸å±å·§å¦å®ç°å±
ä¸
QWidget *widget = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);
layout->addWidget(progress);
widget->setLayout(layout);
ui->tableWidget->setCellWidget(0, 0, widget);
- å¾å¤æ¶åéè¦å¨å·²ç¥èæ¯è²çæ åµä¸ï¼è½å¤æ¸ æ°çç»å¶æåï¼è¿ä¸ªæ¶åéè¦è®¡ç®å¯¹åºçæåé¢è²ã
//æ ¹æ®èæ¯è²èªå¨è®¡ç®åéçåæ¯è²
double gray = (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255;
QColor textColor = gray > 0.5 ? Qt::black : Qt::white;
- 对QTableViewãQTableWidgetãQTreeViewãQTreeWidgetç¦ç¨åæå¨ã
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);
ui->treeView->header()->setResizeMode(0, QHeaderView::Fixed);
#else
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Fixed);
#endif
- ä»Qt4转å°Qt5ï¼æäºç±»çæ¹æ³å·²ç»åºå¼æè è¿æ¶äºï¼å¦ææ³è¦å¨Qt5ä¸å¯ç¨Qt4çæ¹æ³ï¼æ¯å¦QHeadVewçsetMovableï¼å¯ä»¥å¨ä½ çproæè priæ件ä¸å ä¸ä¸è¡å³å¯ï¼DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
09ï¼081-090
- Qtä¸çQColor对é¢è²å°è£ çå¾å®ç¾ï¼æ¯æåç§è½¬æ¢ï¼æ¯å¦rgbãhsbãcmyãhslï¼å¯¹åºçæ¯toRgbãtoHsvãtoCmykãtoHslï¼è¿æ¯æéæ度设置ï¼é¢è²å¼è¿è½è½¬æ16è¿å¶æ ¼å¼æ¾ç¤ºã
QColor color(255, 0, 0, 100);
qDebug() << color.name() << color.name(QColor::HexArgb);
//è¾åº #ff0000 #64ff0000
- QVariantç±»åå¼å¸¸ç强大ï¼å¯ä»¥è¯´æ¯ä¸è½çç±»åï¼å¨è¿è¡é ç½®æ件çåå¨çæ¶åï¼ç»å¸¸ä¼ç¨å°QVariantç转æ¢ï¼QVarianté»è®¤èªå¸¦äºtoStringãtoFloatçåç§è½¬æ¢ï¼ä½æ¯è¿æ¯ä¸å¤ï¼æ¯å¦ææ¶åéè¦ä»QVariant转å°QColorï¼èå´æ²¡ææä¾toColorçå½æ°ï¼è¿ä¸ªæ¶åå°±è¦ç¨å°ä¸è½åæ³ã
if (variant.typeName() == "QColor") {
QColor color = variant.value<QColor>();
QFont font = variant.value<QFont>();
QString nodeValue = color.name(QColor::HexArgb);
}
-
Qtä¸çQStringåconst char *ä¹é´è½¬æ¢ï¼æ好ç¨toStdString().c_str()èä¸æ¯toLocal8Bit().constData()ï¼æ¯å¦å¨setPropertyä¸å¦æç¨åè ï¼å符串ä¸æå°±ä¼ä¸æ£ç¡®ï¼è±ææ£å¸¸ã
-
Qtçä¿¡å·æ§½æºå¶é常çé¼ï¼ä¹æ¯Qtçç¬ç¹çæ ¸å¿åè½ä¹ä¸ï¼ææ¶åæ们å¨å¾å¤çªä½ä¸ä¼ éä¿¡å·æ¥å®ç°æ´æ°æè å¤çï¼å¦æçªä½å±çº§æ¯è¾å¤ï¼æ¯å¦çªä½Açç¶ç±»æ¯çªä½Bï¼çªä½Bçç¶ç±»æ¯çªä½Cï¼çªä½Cæ个åçªä½Dï¼å¦æçªä½Aä¸ä¸ªä¿¡å·è¦ä¼ éç»çªä½Dï¼é®é¢æ¥äºï¼å¿ é¡»å ç»è¿çªä½Bä¸è½¬å°çªä½Cåå°çªä½Dæè¡ï¼è¿æ ·çè¯åç§ä¿¡å·å ³èä¿¡å·çconnectä¼é常å¤èä¸ç®¡çèµ·æ¥æ¯è¾ä¹±ï¼å¯ä»¥èèå¢å ä¸ä¸ªå ¨å±çåä¾ç±»AppEventï¼å ¬å ±çä¿¡å·æ¾è¿éï¼ç¶åçªä½A对åºä¿¡å·ç»å®å°AppEventï¼çªä½Dç»å®AppEventçä¿¡å·å°å¯¹åºç槽å½æ°å³å¯ï¼å¹²åæ¸ ç½æ´æ´ã
-
QTextEditå³é®èåé»è®¤è±æçï¼å¦ææ³è¦ä¸ææ¾ç¤ºï¼å è½½widgets.qmæ件å³å¯ï¼ä¸ä¸ªQtç¨åºä¸å¯ä»¥å®è£ å¤ä¸ªç¿»è¯æ件ï¼ä¸å²çªã
-
Qtä¸æä¸ªå ¨å±çç¦ç¹åæ¢ä¿¡å·focusChangedï¼å¯ä»¥ç¨å®åèªå®ä¹çè¾å ¥æ³ãQt4ä¸é»è®¤ä¼å®è£ è¾å ¥æ³ä¸ä¸æï¼æ¯å¦å¨mainå½æ°æå°a.inputContextä¼æ¾ç¤ºå¼ï¼è¿ä¸ªé»è®¤å®è£ çè¾å ¥æ³ä¸ä¸æï¼ä¼æ¦æªä¸¤ä¸ªçé¼çä¿¡å·QEvent::RequestSoftwareInputPanelåQEvent::CloseSoftwareInputPanelï¼ä»¥è³äºå°±ç®ä½ å®è£ äºå ¨å±çäºä»¶è¿æ»¤å¨ä¾ç¶è¯å«ä¸å°è¿ä¸¤ä¸ªä¿¡å·ï¼ä½ åªéè¦å¨mainå½æ°æ§è¡a.setInputContext(0)å³å¯ï¼æææ¯å®è£ è¾å ¥æ³ä¸ä¸æ为空ãQt5.7以åæä¾äºå ç½®çè¾å ¥æ³ï¼å¯ä»¥éè¿å¨mainå½æ°æåé¢å ä¸ qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); æ¥å¯ç¨ã
-
å¨Qt5.10以åï¼è¡¨æ ¼æ§ä»¶QTableWidgetæè QTableViewçé»è®¤æå°å宽æ¹æäº15ï¼ä»¥åççæ¬æ¯0ï¼æ以å¨æ°ççqtä¸ï¼å¦æè®¾ç½®è¡¨æ ¼çå宽è¿å°ï¼ä¸ä¼åºç¨ï¼åçæ¯æå°çå宽ãæ以å¦æè¦è®¾ç½®æ´å°çå宽éè¦éæ°è®¾ç½®ui->tableView->horizontalHeader()->setMinimumSectionSize(0);
-
Qtæºç ä¸å ç½®äºä¸äºæªå ¬å¼çä¸è½ç´æ¥ä½¿ç¨çé»ç§æï¼é½èå¨å¯¹åºæ¨¡åçprivateä¸ï¼æ¯å¦gui-private widgets-privateçï¼æ¯å¦zipæ件解åç±»QZipReaderãå缩类QZipWriterå°±å¨gui-private模åä¸ï¼éè¦å¨proä¸å¼å ¥QT += gui-privateæè½ä½¿ç¨ã
#include "QtGui/private/qzipreader_p.h"
#include "QtGui/private/qzipwriter_p.h"
QZipReader reader(dirPath);
QString path("");
//解åæ件夹å°å½åç®å½
reader.extractAll(path);
//æ件夹å称
QZipReader::FileInfo fileInfo = reader.entryInfoAt(0);
//解åæ件
QFile file(filePath);
file.open(QIODevice::WriteOnly);
file.write(reader.fileData(QString::fromLocal8Bit("%1").arg(filePath)));
file.close();
reader.close();
QZipWriter *writer = new QZipWriter(dirPath);
//æ·»å æ件夹
writer->addDirectory(unCompress);
//æ·»å æ件
QFile file(filePath);
file.open(QIODevice::ReadOnly);
writer->addFile(data, file.readAll());
file.close();
writer->close();
-
ç论ä¸ä¸²å£åç½ç»æ¶åæ°æ®é½æ¯é»è®¤å¼æ¥çï¼æä½ç³»ç»èªå¨è°åº¦ï¼å®å ¨ä¸ä¼å¡ä½çé¢ï¼ç½ä¸é£äºè¯´æ¶åæ°æ®å¡ä½çé¢ä¸»çº¿ç¨çé½æ¯ä¸æ£ç¡®çï¼çæ£çèæ¶æ¯å¨è¿ç®ä»¥åè¿ç®åçå¤çï¼èä¸æ¯æ¶åæ°æ®ï¼å¨ä¸äºå°æ°æ®éè¿ç®å¤çç项ç®ä¸ï¼ä¸è¬ä¸å»ºè®®å¨ç¨çº¿ç¨å»å¤çï¼çº¿ç¨éè¦è°åº¦å¼éçï¼ä¸è¦ä»ä¹ä¸è¥¿é½å¾çº¿ç¨éè¾¹æï¼çº¿ç¨ä¸æ¯ä¸è½çãåªæå½çæ£éè¦å°ä¸äºå¾èæ¶çæä½æ¯å¦ç¼ç 解ç çï¼æéè¦ç§»å°çº¿ç¨å¤çã
-
å¨æé å½æ°ä¸è·åæ§ä»¶ç宽é«å¾å¯è½æ¯ä¸æ£ç¡®çï¼éè¦å¨æ§ä»¶é¦æ¬¡æ¾ç¤ºä»¥ååè·åææ¯æ£ç¡®çï¼æ§ä»¶æ¯å¨é¦æ¬¡æ¾ç¤ºä»¥åæä¼è®¾ç½®å¥½æ£ç¡®ç宽é«å¼ï¼è®°ä½æ¯å¨é¦æ¬¡æ¾ç¤ºä»¥åï¼èä¸æ¯æé å½æ°æè ç¨åºå¯å¨å¥½ä»¥åï¼å¦æç¨åºå¯å¨å¥½ä»¥åæäºå®¹å¨æ§ä»¶æ¯å¦QTabWidgetä¸ç没ææ¾ç¤ºç页é¢çæ§ä»¶ï¼ä½ å»è·å宽é«å¾å¯è½ä¹æ¯ä¸æ£ç¡®çï¼ä¸æ ä¸å¤±çåæ³å°±æ¯é¦æ¬¡æ¾ç¤ºä»¥åå»è·åã
10ï¼091-100
-
æ°æ®åºå¤çä¸è¬å»ºè®®å¨ä¸»çº¿ç¨ï¼å¦æéè¦å¨å ¶ä»çº¿ç¨ï¼å¡å¿ è®°å¾æå¼æ°æ®åºä¹è¦å¨é£ä¸ªçº¿ç¨ï¼å³å¨é£ä¸ªçº¿ç¨ä½¿ç¨æ°æ®åºå°±å¨é£ä¸ªçº¿ç¨æå¼ï¼ä¸è½æå¼æ°æ®åºå¨ä¸»çº¿ç¨ï¼æ§è¡sqlå¨å线ç¨ï¼å¾å¯è½åºé®é¢ã
-
æ°ççQTcpServerç±»å¨64ä½çæ¬çQtä¸å¾å¯è½ä¸ä¼è¿å ¥incomingConnectionå½æ°ï¼é£æ¯å 为Qt5对åºçincomingConnectionå½æ°åæ°åäºï¼ç±ä¹åçintæ¹æäºqintptrï¼æ¹æqintptræ个好å¤ï¼å¨32ä½ä¸èªå¨æ¯quint32èå¨64ä½ä¸èªå¨æ¯quint64ï¼å¦æå¨Qt5ä¸ç»§ç»åçåæ°æ¯intåå¨32ä½ä¸æ²¡æé®é¢å¨64ä½ä¸ææé®é¢ï¼æ以为äºå ¼å®¹Qt4åQt5ï¼å¿ é¡»æç §ä¸ä¸æ ·çåæ°åã
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
void incomingConnection(qintptr handle);
#else
void incomingConnection(int handle);
#endif
-
Qtæ¯æææççé¢æ§ä»¶æ¯å¦QPushButtonãQLineEditèªå¨å ³è on_æ§ä»¶å_ä¿¡å·(åæ°) ä¿¡å·æ§½ï¼æ¯å¦æé®çåå»ä¿¡å· on_pushButton_clicked()ï¼ç¶åç´æ¥å®ç°æ§½å½æ°å³å¯ã
-
QWebEngineViewæ§ä»¶ç±äºä½¿ç¨äºopenglï¼å¨æäºçµèä¸å¯è½ç±äºopenglç驱å¨è¿ä½ä¼å¯¼è´è±å±æè åç§å¥å¥æªæªçé®é¢ï¼æ¯å¦showfullscreençæ åµä¸é¼ æ å³é®å¤±æï¼éè¦å¨mainå½æ°å¯ç¨è½¯ä»¶opengl渲æã
#if (QT_VERSION > QT_VERSION_CHECK(5,4,0))
//ä¸é¢ä¸¤ç§æ¹æ³é½å¯ä»¥,Qté»è®¤éç¨çæ¯AA_UseDesktopOpenGL
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
//QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
#endif
QApplication a(argc, argv);
å¦å¤ä¸ä¸ªæ¹æ³è§£å³ å ¨å±+QWebEngineViewæ§ä»¶ä¸èµ·ä¼äº§çå³é®èåæ æ³å¼¹åºçbug,éè¦ä¸ç§»ä¸ä¸ªåç´
QRect rect = qApp->desktop()->geometry();
rect.setY(-1);
rect.setHeight(rect.height());
this->setGeometry(rect);
- QStyleå ç½®äºå¾å¤æ¹æ³ç¨å¤å¾å¤§ï¼æ¯å¦ç²¾ç¡®è·åæ»å¨æ¡é¼ æ æä¸å¤çå¼ã
QStyle::sliderValueFromPosition(minimum(), maximum(), event->x(), width());
- ç¨QFile读åæ件çæ¶åï¼æ¨èç¨QTextStreamæ件æµçæ¹å¼æ¥è¯»åæ件ï¼é度快å¾å¤ï¼åºæ¬ä¸ä¼æ30%çæåï¼æ件è¶å¤§æ§è½åºå«è¶å¤§ã
//ä»æ件å è½½è±æå±æ§ä¸ä¸æå±æ§å¯¹ç
§è¡¨
QFile file(":/propertyname.txt");
if (file.open(QFile::ReadOnly)) {
//QTextStreamæ¹æ³è¯»åé度è³å°å¿«ç¾åä¹30
#if 0
while(!file.atEnd()) {
QString line = file.readLine();
appendName(line);
}
#else
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
appendName(line);
}
#endif
file.close();
}
- ç¨QFile.readAll()读åQSSæ件é»è®¤æ¯ANSIæ ¼å¼ï¼ä¸æ¯æUTF8ï¼å¦æå¨QtCreatorä¸æå¼qssæ件æ¥ç¼è¾ä¿åï¼è¿æ ·å¾å¯è½å¯¼è´qsså 载以å没æææã
void frmMain::initStyle()
{
//å è½½æ ·å¼è¡¨
QString qss;
//QFile file(":/qss/psblack.css");
//QFile file(":/qss/flatwhite.css");
QFile file(":/qss/lightblue.css");
if (file.open(QFile::ReadOnly)) {
#if 1
//ç¨QTextStream读åæ ·å¼æ件ä¸ç¨åºåæ件ç¼ç 带bomä¹è¡
QStringList list;
QTextStream in(&file);
//in.setCodec("utf-8");
while (!in.atEnd()) {
QString line;
in >> line;
list << line;
}
qss = list.join("\n");
#else
//ç¨readAll读åé»è®¤æ¯æçæ¯ANSIæ ¼å¼,å¦æä¸å°å¿ç¨creatoræå¼ç¼è¾è¿äºå¾å¯è½æä¸å¼
qss = QLatin1String(file.readAll());
#endif
QString paletteColor = qss.mid(20, 7);
qApp->setPalette(QPalette(QColor(paletteColor)));
qApp->setStyleSheet(qss);
file.close();
}
}
- QStringå ç½®äºå¾å¤è½¬æ¢å½æ°ï¼æ¯å¦å¯ä»¥è°ç¨toDouble转为doubleæ°æ®ï¼ä½æ¯å½ä½ 转å®å¹¶æå°çæ¶åä½ ä¼åç°ç²¾ç¡®å°äºï¼åªå©ä¸ä¸ä½äºï¼å ¶å®åå§æ°æ®è¿æ¯å®æ´ç精确度çï¼åªæ¯æå°çæ¶åä¼åæäºä¸ä½ï¼å¦æè¦ä¿è¯å®æ´ç精确度ï¼å¯ä»¥è°ç¨ qSetRealNumberPrecision å½æ°è®¾ç½®ç²¾ç¡®åº¦ä½æ°å³å¯ã
QString s1, s2;
s1 = "666.5567124";
s2.setNum(888.5632123, 'f', 7);
qDebug() << qSetRealNumberPrecision(10) << s1.toDouble() << s2.toDouble();
- ç¨QScriptValueIterator解ææ°æ®çæ¶åï¼ä¼åç°æ»æ¯ä¼å¤ä¸ä¸ªèç¹å 容ï¼å¹¶ä¸å 容为空ï¼å¦æéè¦è·³è¿åå¢å ä¸è¡ä»£ç ã
while (it.hasNext()) {
it.next();
if (it.flags() & QScriptValue::SkipInEnumeration)
continue;
qDebug() << it.name();
}
- setPixmapæ¯æç³ç³çè´´å¾æ¹å¼ï¼ä¸è¬åªç¨æ¥ç®åçä¸æ¯å¾é¢ç¹çè´´å¾ï¼é¢ç¹ç建议painterç»å¶ï¼é»è®¤åç¼å²ï¼å¨é«çº§ç¹ç¨openglç»å¶ï¼å©ç¨GPUã
11ï¼101-110
-
å¦æéè¦å¨å°ºå¯¸æ¹åçæ¶åä¸éç»çªä½ï¼å设置å±æ§å³å¯ this->setAttribute(Qt::WA_StaticContents, true); è¿æ ·å¯ä»¥é¿å 对已ç»æ¾ç¤ºåºåçéæ°ç»å¶ã
-
é»è®¤ç¨åºä¸è·åç¦ç¹ä»¥åä¼æèè¾¹æ¡ï¼å¦æççè§å¾ç¢ç¼ä¸èæå¯ä»¥å»æï¼è®¾ç½®æ ·å¼å³å¯ï¼setStyleSheet("*{outline:0px;}");
-
Qtè¡¨æ ¼æ§ä»¶ä¸äºå¸¸ç¨ç设置å°è£ ï¼QTableWidget继æ¿èªQTableViewï¼æ以ä¸é¢è¿ä¸ªå½æ°æ¯æä¼ å ¥QTableWidgetã
void QtHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit)
{
//å¥æ°å¶æ°è¡é¢è²äº¤æ¿
tableView->setAlternatingRowColors(false);
//åç´è¡¨å¤´æ¯å¦å¯è§
tableView->verticalHeader()->setVisible(headVisible);
//éä¸ä¸è¡è¡¨å¤´æ¯å¦å ç²
tableView->horizontalHeader()->setHighlightSections(false);
//æåä¸è¡æ伸填å
tableView->horizontalHeader()->setStretchLastSection(true);
//è¡æ é¢æå°å®½åº¦å°ºå¯¸
tableView->horizontalHeader()->setMinimumSectionSize(0);
//è¡æ é¢æ大é«åº¦
tableView->horizontalHeader()->setMaximumHeight(rowHeight);
//é»è®¤è¡é«
tableView->verticalHeader()->setDefaultSectionSize(rowHeight);
//éä¸æ¶ä¸è¡æ´ä½éä¸
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
//åªå
许éæ©å个
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
//表头ä¸å¯åå»
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
tableView->horizontalHeader()->setSectionsClickable(false);
#else
tableView->horizontalHeader()->setClickable(false);
#endif
//é¼ æ æä¸å³è¿å
¥ç¼è¾æ¨¡å¼
if (edit) {
tableView->setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked);
} else {
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
}
- å¨ä¸äºå¤§ç项ç®ä¸ï¼å¯è½åµå¥äºå¾å¤å项ç®ï¼ææ¶åä¼éå°å项ç®ä¾èµå ¶ä»å项ç®çæ¶åï¼æ¯å¦ä¸é¨åå项ç®ç¨æ¥çæå¨æåºï¼ä¸é¨åå项ç®ä¾èµè¿ä¸ªå¨æåºè¿è¡ç¼è¯ï¼æ¤æ¶å°±éè¦å项ç®æç §é¡ºåºç¼è¯æè 设置好ä¾èµè§åã
TEMPLATE = subdirs
#设置orderedåæ°ä»¥åä¼ä¾æ¬¡ç¼è¯ projA projB projC
CONFIG += ordered
SUBDIRS += projA
SUBDIRS += projB
SUBDIRS += projC
#è¿å¯ä»¥éè¿è®¾ç½®dependsæå®æ个项ç®ä¾èµ æ¯å¦ä¸é¢æå®projBä¾èµprojA
projB.depends = projA
projC.depends = projA
projD.depends = projC
- MSVCç¼è¯å¨çéæ©è¯´æ
- å¦ææ¯32ä½çQtåç¼è¯å¨éæ©x86å¼å¤´ç
- å¦ææ¯64ä½çQtåç¼è¯å¨éæ©amd64å¼å¤´ç
- å ·ä½æ¯çå®è£ çQtæ建å¥ä»¶çæ¬ä»¥åç®æ è¿è¡å¹³å°çç³»ç»ä½æ°åæ¶æ
- ä¸è¬ç°å¨ççµèé»è®¤ä»¥64ä½çå± å¤ï¼éæ©amd64å³å¯
- å¦æç¨æ·éè¦å ¼å®¹32ä½çç³»ç»å建议éæ©32ä½çQtï¼è¿æ ·å³å¯å¨32ä½ä¹å¯ä»¥å¨64ä½ç³»ç»è¿è¡
- 诸è大佬补å ï¼x86/x64é½æ¯ç¼è¯ç¯å¢åè¿è¡ç¯å¢ç¸åï¼æ²¡ææã带ä¸å线çå°±æ¯äº¤åç¼è¯ï¼åé¢æ¯ç¼è¯ç¯å¢ï¼åé¢æ¯è¿è¡ç¯å¢ã
å称 | 说æ |
---|---|
x86 | 32/64ä½ç³»ç»ä¸ç¼è¯å¨32/64ä½ç³»ç»ä¸è¿è¡ |
x86_amd64 | 32/64ä½ç³»ç»ä¸ç¼è¯å¨64ä½ç³»ç»ä¸è¿è¡ |
x86_arm | 32/64ä½ç³»ç»ä¸ç¼è¯å¨armç³»ç»ä¸è¿è¡ |
amd64 | 64ä½ç³»ç»ä¸ç¼è¯å¨64ä½ç³»ç»ä¸è¿è¡ |
amd64_x86 | 64ä½ç³»ç»ä¸ç¼è¯å¨32/64ä½ç³»ç»ä¸è¿è¡ |
amd64_arm | 64ä½ç³»ç»ä¸ç¼è¯å¨armç³»ç»ä¸è¿è¡ |
- å¾å¤æ¶åç¨QDialogçæ¶åä¼åç°é»å¡äºæ¶æ¯ï¼èæçæ¶åæ们å¸ææ¯åå°çä¸äºæ¶æ¯ç»§ç»è¿è¡ä¸è¦ç»æ¢ï¼æ¤æ¶éè¦å个设置ã
QDialog dialog;
dialog.setWindowModality(Qt::WindowModal);
å¾å¤åå¦è çè³å å¹´å·¥ä½ç»éªç人ï¼å¯¹å¤çº¿ç¨æå¾æ·±ç误解å滥ç¨ï¼å°¤å ¶æ¯å¨ä¸²å£åç½ç»éä¿¡è¿åï¼ä»ä¹é½å¾å¤çº¿ç¨éé¢ä¸¢ï¼ä¸æ¦éå°çé¢å¡ï¼å°±ææ°æ®æ¶åå¥çé½æå°å¤çº¿ç¨éé¢å»ï¼æ®ä¸ç¥ç»å¤§é¨åæ¶åé£æ ¹æ¬æ²¡å¥ç¨ï¼å 为没æ¾å°åºé®é¢çæ ¹æºã
- å¦æä½ æ²¡æ使ç¨wait***å½æ°çè¯ï¼å¤§é¨åççé¢å¡é½åºå¨æ°æ®å¤çåå±ç¤ºä¸ï¼æ¯å¦ä¼ è¿æ¥çæ¯ä¸å¼ å¾ççæ°æ®ï¼ä½ éè¦å°è¿äºæ°æ®è½¬æå¾çï¼è¿ä¸ªè¯å®æ¯èæ¶çï¼
- è¿æå°±æ¯å°±æ¶å°çæ°æ®æ²çº¿ç»å¶åºæ¥ï¼å¦æè¿äºé¢ç¹æè é´éè¿çï¼è¯å®ä¼ç»UIé æå¾å¤§çååçï¼æ好çåæ³æ¯è§£å³å¦ä½ä¸è¦é¢ç¹ç»å¶UIæ¯å¦å并æ°æ®ä¸èµ·ç»å¶çï¼
- å¦ææ¯å 为ç»å¶UIé æçå¡ï¼é£å¤çº¿ç¨ä¹æ¯æ²¡å¥ç¨çï¼å 为UIåªè½å¨ä¸»çº¿ç¨ï¼
- 串å£åç½ç»çæ°æ®æ¶åé»è®¤é½æ¯å¼æ¥çï¼ç±æä½ç³»ç»è°åº¦çï¼å¦ææ°æ®å¤çå¤æèä¸æ°æ®é大ï¼ä½ è¦åçæ¯å°æ°æ®å¤çæ¾å°å¤çº¿ç¨ä¸ï¼
- å¦æ没æä¸¥æ ¼çæ°æ®åæ¥éæ±ï¼æ ¹æ¬ä¸éè¦è°ç¨wait***ä¹ç±»çå½æ°æ¥ç«å³åéåæ¥æ¶æ°æ®ï¼å®é éæ±ä¸å¤§é¨åçåºç¨åºæ¯å ¶å®å¼æ¥æ¶åæ°æ®å°±è¶³å¤äºï¼
- æä¸¥æ ¼æ°æ®åæ¥éæ±çåºæ¯è¿æ¯æ¾å°å¤çº¿ç¨ä¼å¥½ä¸äºï¼ä¸ç¶ä½ wait***å°±å¡å¨é£è¾¹äºï¼
- å¤çº¿ç¨æ¯éè¦å ç¨ç³»ç»èµæºçï¼ç论ä¸æ¥è¯´ï¼å¦æ线ç¨æ°éè¶ è¿äºCPUçæ ¸å¿æ°éï¼å ¶å®å¤çº¿ç¨è°åº¦å¯è½è±è´¹çæ¶é´æ´å¤ï¼åä½å¨ä½¿ç¨è¿ç¨ä¸è¦æè¡¡å©å¼ï¼
- å次强è°ï¼ä¸è¦ææQtçç½ç»éä¿¡æ¯æé«å¹¶åï¼æå¤å°1000个è½æ£å¸¸å·¥ä½å°±ä¸äºå¤§åï¼ä¸è¬å»ºè®®500以å çè¿æ¥æ°ãæ大éé«å¹¶åçéæ±è¯·ç¨ç¬¬ä¸æ¹åºæ¯å¦swooleçã
-
å¨åµå ¥å¼linuxä¸ï¼å¦æ设置äºæ è¾¹æ¡çªä½ï¼è该çªä½ä¸åæææ¬æ¡ä¹ç±»çï¼åç°æ²¡æ³äº§çç¦ç¹è¿è¡è¾å ¥ï¼æ¤æ¶éè¦ä¸»å¨æ¿æ´»çªä½æè¡ã
//è¿ç§æ¹å¼è®¾ç½®çæ è¾¹æ¡çªä½å¨åµå
¥å¼è®¾å¤ä¸æ æ³äº§çç¦ç¹
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
//éè¦å¨show以å主å¨æ¿æ´»çªä½
w->show();
w->activateWindow();
-
QStringçreplaceå½æ°ä¼æ¹ååå符串ï¼åè®°ï¼ä»å¨è¿åæ¿æ¢åçæ°å符串çåæ¶ä¹ä¼æ¹ååå符串ï¼æçä¹ä¹ï¼
-
QGraphicsEffectç±»çç¸å ³ææå¾ç«ï¼å¯ä»¥å®ç°å¾å¤æææ¯å¦éæãæ¸åãé´å½±çï¼ä½æ¯è¯¥ç±»å¾èCPUï¼å¦æä¸æ¯ç¹å«éè¦ä¸è¬ä¸å»ºè®®ç¨ï¼å°±ç®ç¨ä¹æ¯è¦ç¨å¨è¯¥é¨ä»¶åæä¸ä¼åçé¢ç¹ç»å¶çåºæ¯ï¼ä¸ç¶ä¼è®©ä½ åæå¨åæã
12ï¼111-120
- å¨ä¸åçå¹³å°ä¸æ件路å¾çææ ä¹æ¯ä¸ä¸æ ·çï¼æ¯å¦linuxç³»ç»ä¸è¬é½æ¯ / ææ ï¼èå¨windowsä¸é½æ¯ \ 两个åææ ï¼Qtæ¬èº«ç¨åºå é¨æ 论å¨winè¿æ¯linuxé½æ¯æ / ææ çè·¯å¾ï¼ä½æ¯ä¸äºç¬¬ä¸æ¹åºçè¯å¯è½éè¦è½¬æ¢æ对åºç³»ç»çè·¯å¾ï¼è¿å°±éè¦ç¨å°ææ 转æ¢ï¼Qtå½ç¶å 置类æ¹æ³ã
QString path = "C:/temp/test.txt";
path = QDir::toNativeSeparators(path);
//è¾åº C:\\temp\\test.txt
QString path = "C:\\temp\\test.txt";
path = QDir::toNativeSeparators(path);
//è¾åº C:/temp/test.txt
- å·§ç¨QMetaObject::invokeMethodæ¹æ³å¯ä»¥å®ç°å¾å¤ææï¼å æ¬åæ¥åå¼æ¥æ§è¡ï¼å¾å¤§ç¨åº¦ä¸è§£å³äºè·¨çº¿ç¨å¤çä¿¡å·æ§½çé®é¢ãæ¯å¦æ个åºç¨åºæ¯æ¯å¨åè°ä¸ï¼éè¦å¼æ¥è°ç¨ä¸ä¸ªpublicå½æ°ï¼å¦æç´æ¥è°ç¨çè¯ä¼åç°ä¸æåï¼æ¤æ¶éè¦ä½¿ç¨ QMetaObject::invokeMethod(obj, "fun", Qt::QueuedConnection); è¿ç§æ¹å¼æ¥å°±å¯ä»¥ã
- invokeMethodå½æ°æå¾å¤éè½½åæ°ï¼å¯ä»¥ä¼ å ¥è¿åå¼åæ§è¡æ¹æ³çåæ°çã
- invokeMethodå½æ°ä¸ä» æ¯æ槽å½æ°è¿æ¯æä¿¡å·ï¼èä¸è¿é¼å± ç¶æ¯çº¿ç¨å®å ¨çï¼å¯ä»¥å¨çº¿ç¨ä¸æ¾å¿ä½¿ç¨ï¼çé¼ï¼
- æµè¯ä¸æ¥åç°åªè½æ§è¡signalsæè slotsæ è¯çæ¹æ³ã
- é»è®¤å¯ä»¥æ§è¡private(protected/public) slotsä¸çå½æ°ï¼ä½æ¯ä¸è½æ§è¡private(protected/public)ä¸çå½æ°ã
- æ¯æ»è¡¥å ï¼åæå¿ é¡»æ¯slotsæè signalsæ 注çå½æ°ï¼ä¸æ¯æ 注çå½æ°ä¸å¨å ä¿¡æ¯å¯¼è´æ æ³æ¥æ¾ï¼æ§è¡ä¹åä¼æ示No such methodã
- 2021-11-06è¡¥å ï¼å¦æè¦æ§è¡private(protected/public)ä¸çå½æ°ï¼éè¦å½æ°åé¢å ä¸ Q_INVOKABLE å ³é®åï¼ä»å¤©åå¦å°äºï¼å¿ é¡»å é¸¡è ¿ã
- å ¶å®è¿æ ·çä¸æ¥ï¼å°±æ¯ä»»ä½æ¹æ³å½æ°é½è½æ§è¡äºï¼è¿å°±è¶ è¶äºprivate(protected/public)çæééå®äºï¼ç¸å½äºä¸ä¸ªç±»çç§æå½æ°ç¨äº Q_INVOKABLE å ³é®å修饰ä¹å¯ä»¥è¢« invokeMethod æ§è¡ï¼åååã
//头æ件声æä¿¡å·å槽å½æ°
signals:
void sig_test(int type,double value);
private slots:
void slot_test(int type, double value);
private:
Q_INVOKABLE void fun_test(int type, double value);
//æé å½æ°å
³èä¿¡å·æ§½
connect(this, SIGNAL(sig_test(int, double)), this, SLOT(slot_test(int, double)));
//åå»æé®è§¦åä¿¡å·å槽ï¼è¿éæ¯åæ¶ä¸¾ä¾ä¿¡å·æ§½é½å¯ä»¥
void MainWindow::on_pushButton_clicked()
{
QMetaObject::invokeMethod(this, "sig_test", Q_ARG(int, 66), Q_ARG(double, 66.66));
QMetaObject::invokeMethod(this, "slot_test", Q_ARG(int, 88), Q_ARG(double, 88.88));
QMetaObject::invokeMethod(this, "fun_test", Q_ARG(int, 99), Q_ARG(double, 99.99));
}
//ä¼æå° 66 66.66ã88 88.88
void MainWindow::slot_test(int type, double value)
{
qDebug() << type << value;
}
//ä¼æå° 99 99.99
void MainWindow::fun_test(int type, double value)
{
qDebug() << type << value;
}
-
Qt5ä¸çä¿¡å·æ¯publicçï¼å¯ä»¥å¨éè¦çå°æ¹ç´æ¥emitå³å¯ï¼èå¨Qt4ä¸ä¿¡å·æ¯protectedçï¼ä¸è½ç´æ¥ä½¿ç¨ï¼éè¦å®ä¹ä¸ä¸ªpublicå½æ°æ¥emitã
-
Qt5.15çæ¬å¼å§å®æ¹ä¸åæä¾å®è£ å ï¼åªæä¾æºç ï¼å¯ä»¥èªè¡ç¼è¯æè å¨çº¿å®è£ ï¼ä¹å¯ä»¥å°å¨çº¿å®è£ 好ç离线æ件æå æ·è´å°çµèä¸ä½¿ç¨ï¼ï¼ä¼°è®¡æ¯æ¬¡ç¼è¯åç§çæ¬å¤ªéº»ç¦ï¼æ´å¤çæ¯ä¸ºäºç»è®¡æ¶éç¨æ·ä½¿ç¨ä¿¡æ¯æ¯å¦éè¿å¨çº¿å®è£ ï¼åæå¯è½ä¼éæ¥å 大åä¸åå度ã
-
ææ¶åæ们éè¦å¤æå½åQtçæ¬æ没ææ个模åå¯ä»¥ä½¿ç¨qtHaveModuleï¼Qt5æ°å¼å ¥çå¤æï¼æ¥å¤æï¼å¦æè¦å¤æèªå·±ç项ç®ä¸æ没æ QT += çæ¹å¼æ·»å ç模åï¼å¯ä»¥ç¨ containsæ¥å¤æã
qtHaveModule(webenginewidgets) {
message("å½åQtåºææ¾å° webenginewidgets 模å")
}
!qtHaveModule(webkit) {
message("å½åQtåºæ²¡ææ¾å° webkit 模å")
}
contains(QT, network) {
message("å½å项ç®å·²ç»å¼å
¥ network 模å")
}
!contains(QT, widgets) {
message("å½å项ç®æ²¡æå¼å
¥ widgets 模å")
}
- c++11æ°å¼å ¥äºåå§åç¬¦ä¸²æ ¼å¼ï¼ç¨æ·é¿å å¨å符串ä¸å å ¥è½¬ä¹å符\ï¼å¯ä»¥ç¨äºè¡¨ç¤ºjsonå符串çåºæ¯ã
QString s1 = R"(test\001.jpg)";
s1.replace("\\", "#");
qDebug()<< s1;
//ç»æ test#001.jpg
-
å®åä¸æå°ä¿¡æ¯å»ºè®®ä½¿ç¨ qInfo() èä¸æ¯ qDebug() ï¼qInfo()ææææã
-
Qtçé»è®¤å®æ¶å¨ç²¾åº¦ä¸å¤é«ï¼æ¯å¦åºç¨åºæ¯æ¯1åéä¿åä¸æ¡è®°å½æè æ件ï¼å½ä½ ç¨é»è®¤çå®æ¶å¨çæ¶åä½ ä¼åç°æäºæ¶åæ¯60ç§èæäºæ¯59ç§éæºçï¼å¦æ客æ·æè¦æ±è¿å°±éè¦è®¾ç½®ç²¾åº¦äºãå½ç¶æ们æåçç»å¤§é¨å项ç®ä¹ä¸éè¦ç²¾åº¦é常é«çå®æ¶å¨ï¼æ¯ç«ç²¾åº¦è¶é«ï¼å ç¨çç³»ç»èµæºå¯è½è¶å¤§ï¼ï¼å¦æéè¦è®¾ç½®æ´é«ç精度å¯ä»¥è®¾ç½® setTimerType(Qt::PreciseTimer)ãQtæ两ç§å®æ¶å¨å¤çï¼ä¸ç§æ¯QTimerç±»ï¼è¿æä¸ç§æ¯QObject类就å ç½®çtimeeventäºä»¶ï¼å¦ææ¯QObjectç±»çå®æ¶å¨è¦è®¾ç½®çè¯è°ç¨ startTimer(interval, Qt::PreciseTimer);
- Qt::PreciseTimer 精确çå®æ¶å¨ï¼å°½éä¿æ毫ç§ç²¾åº¦ã
- Qt::CoarseTimer ç²ç¥çå®æ¶å¨ï¼å°½éä¿æ精度å¨æéçæ¶é´é´é5%èå´å ã
- Qt::VeryCoarseTimer å¾ç²ç¥çå®æ¶å¨ï¼åªä¿çå®æ´ç第äºç²¾åº¦ã
- 精度åé«ï¼ä¹ä¾èµå¯¹åºçæä½ç³»ç»ä¸æï¼å设ä¸æéè¦ 5msï¼åå®æ¶å¨ç²¾åº¦ä¸å¯è½é«äº5毫ç§ã
-
QGraphicsEffectç¸å ³ç±»å¾èCPUï¼çè³å¨ç»å¶çæ¶ååæäºå°æ¹æå²çªå¹²æ°ï¼åºæ¬ä¸ä¸å»ºè®®ä½¿ç¨ï¼æ éå¾å·²åªå»ºè®®å°é使ç¨åéé¢ç¹è§¦åç»å¶çå°æ¹ä½¿ç¨ã
-
ç¨QSettings设置注å表ï¼å¦æä¸æ¯ç®¡çå身份è¿è¡ä¼æå° QSettings: failed to set subkey "xxx" (æç»è®¿é®ã)ï¼ä½ éè¦æå¨é¼ æ å³é®ç®¡çå身份è¿è¡å°±å¯ä»¥ã
13ï¼121-130
- QLineEdité¤äºå纯çææ¬æ¡ä»¥å¤ï¼è¿å¯ä»¥åå¾å¤ç¹æ®çå¤çç¨éã
- éå¶è¾å ¥åªè½è¾å ¥IPå°åã
- éå¶è¾å ¥èå´ï¼å¼ºçæ¨èä½¿ç¨ QRegExpValidator æ£å表达å¼æ¥å¤çã
//æ£å¨è¡¨è¾¾å¼éå¶è¾å
¥
QString str = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
ui->lineEdit->setValidator(new QRegExpValidator(QRegExp(str)));
//ç¨äºå ä½
ui->lineEdit->setInputMask("000.000.000.000");
#if 0
//ä¸é¢ä»£ç 设置浮ç¹æ°èå´éå¶å¤±è´¥
ui->lineEdit->setValidator(new QDoubleValidator(20, 50, 1));
#else
//ä¸é¢ä»£ç 设置浮ç¹æ°èå´éå¶æå
QDoubleValidator *validator = new QDoubleValidator(20, 50, 1);
validator->setNotation(QDoubleValidator::StandardNotation);
ui->lineEdit->setValidator(validator);
#endif
//ä¸é¢ä»£ç 设置æ´æ°èå´éå¶æå
ui->lineEdit->setValidator(new QIntValidator(10, 120));
//å
¶å®ä¸é¢ç代ç 缺é·å¾å¤ï¼åªè½éå¶åªè¾å
¥å°æ°ï¼æ æ³è®¾å®æ°å¼èå´ï¼å¾æè
//éè¦æ¥ä¸ªä¸è½ççé¼ç QRegExpValidator
//éå¶æµ®ç¹æ°è¾å
¥èå´ä¸º[-180,180]
QRegExp regexp("^-?(180|1?[0-7]?\\d(\\.\\d+)?)$");
//éå¶æµ®ç¹æ°è¾å
¥èå´ä¸º[-90,90]并éå®ä¸ºå°æ°ä½å4ä½
QRegExp regexp("^-?(90|[1-8]?\\d(\\.\\d{1,4})?)$");
QRegExpValidator *validator = new QRegExpValidator(regexp, this);
ui->lineEdit->setValidator(validator);
- å¨ç»§æ¿èªQAbstractItemViewçæ§ä»¶ä¸ï¼æ¯å¦QTableViewãQTableWidgetï¼å¦æææ¬è¶ è¿å¯¹åºitemç宽度ï¼åä¼èªå¨çç¥å·æ¾ç¤ºï¼æ³è¦å¿«éæ¾ç¤ºå®æ´çææ¬ï¼å¯ä»¥å¨è¯¥ååä¸ä¸ååå²çº¿ä¸é´åå»å³å¯ï¼ä¼èªå¨èªéåºæ¾ç¤ºæ大宽度ï¼å¦ææ¯Qt5.14æè æ´é«çæ¬ï¼ä½ ä¼åç°æ¾ç¤ºçç¥å·ç计ç®è§ååäºï¼å¦ææ¯rtspãhttpä¹ç±»çå¼å¤´çè±æå符串ï¼åæ ·çå宽ä¸ï¼ä¼æåå°±æ¾ç¤ºçç¥å·ï¼æ¯å¦å符串 rtmp://58.200.131.2:1935/livetv/cctv1ï¼ä¼æ¾ç¤ºæ rtmp://... ï¼èå¨æ§çæ¬çQtä¸ä¼æ¾ç¤ºæ rtmp://58.200.131... ï¼å¾å¤æ¶åæ们并ä¸æ³çå°ç¦äººççç¥å·ï¼å¯ä»¥è®¾ç½®åæ¶ã
//åæ¶èªå¨æ¢è¡
tableView->setWordWrap(false);
//è¶
åºææ¬ä¸æ¾ç¤ºçç¥å·
tableView->setTextElideMode(Qt::ElideNone);
- QVideoWidgetææ¾è§é¢ï¼å¯è½ä¼éå°ç»é¢éªççæ åµï¼ææ¾è§é¢ççªä½éè¦è®¾ç½®ä¸ªå±æ§ã
QVideoWidget *videoWidget = new QVideoWidget;
videoWidget->setAttribute(Qt::WA_OpaquePaintEvent);
-
Qt bugæåä¸ä¸ï¼è¿ä¸ªä¸ç¨å¤§æå°æªï¼ä¹åºæ¬ä¸éä¸å°ï¼å¤§é¨åé½æ¯ç¹æ®æ端æ åµç¹å®åºç¨åºæ¯åºç°ï¼çè³ä½ ä¼éå°æäºæ¯debugå¯ä»¥releaseæ¥éï¼æäºreleaseå¯ä»¥debugå´æ¥éçæ åµï¼æç¥å¥çè¿æå æ¯debugæ¥éï¼ç¶åreleaseæ£å¸¸ï¼åè¿åå»ç¨debugåæ£å¸¸ï¼éè¦ç¨releaseæ¿æ´»ä¸ä¸ï¼å¦ä¹ ç¼ç¨çè·¯æ¬æ¥å°±æ¯ä¸æ¡åå洼洼çè·¯ï¼ä¸æå¡«åï¼å°½éè§é¿åï¼å¾å¤æ¶åå¾å¤çèµ·æ¥çåå ¶å®æ¯èªå·±æ²¡æ注æç»è导è´çã
-
Qtè§å¾ä¸é»è®¤æåºæ¯æç §å符串çASCIIæåºçï¼å¦ææ¯IPå°åçè¯ä¼åºç°192.168.1.117æå¨192.168.1.2åé¢çæ åµï¼å¦æè¦è§é¿è¿ç§æ åµï¼ä¸ç§åæ³æ¯åæ«å°¾çå°å转ææ´ååæ¯è¾å¤§å°ï¼ç¼ºç¹æ¯è·¨ç½æ®µå°±æèäºï¼åä¼åºç°192.168.2.65åºç°å¨192.168.1.70åé¢ï¼ç»æ大æ³æ¯å°IPå°å转ææ´ååæ¯è¾å¤§å°ã
QString QtHelper::ipv4IntToString(quint32 ip)
{
QString result = QString("%1.%2.%3.%4").arg((ip >> 24) & 0xFF).arg((ip >> 16) & 0xFF).arg((ip >> 8) & 0xFF).arg(ip & 0xFF);
return result;
}
quint32 QtHelper::ipv4StringToInt(const QString &ip)
{
int result = 0;
if (isIP(ip)) {
QStringList list = ip.split(".");
int ip0 = list.at(0).toInt();
int ip1 = list.at(1).toInt();
int ip2 = list.at(2).toInt();
int ip3 = list.at(3).toInt();
result = ip3 | ip2 << 8 | ip1 << 16 | ip0 << 24;
}
return result;
}
-
å¨ä¸»QWidgetçªä½å¦æç´æ¥qss设置èæ¯å¾ççè¯ï¼é¢è§æ¯å¯è§çï¼è¿è¡å¹¶æ²¡æææï¼ä½ éè¦å¨è¿ä¸ªä¸»widgetä¸åæ¾ä¸ªwidgetï¼å¨æ°çwidgetä¸è®¾ç½®qsså¾çå°±è¡ï¼èå¦ææ¯Dialogæè QMainWindowçªä½æ¯æ¯æç´æ¥è®¾ç½®qssèæ¯å¾çï¼é¢è§åè¿è¡ææä¸è´ã
-
Qtæä¾äºqDebugæºå¶ç´æ¥è¾åºæå°ä¿¡æ¯ï¼è¿ä¸ªå¼¥è¡¥äºQtCreatorè°è¯å¾é¸¡èç缺ç¹ï¼èä¸æ ç¼å¯¹æ¥æ¥å¿é©åï¼ä½¿å¾ç°åºè¿è¡æé´æç §é¢å®çæå°ä¿¡æ¯è¾åºå°æ¥å¿æ件ï¼ææ¶åå¨å¼åé¶æ®µï¼åä¸æ³è¦çå°ä¸å å çæå°ä¿¡æ¯ï¼æ笨çåæ³æ¯ä¸è¡è¡æ³¨éæqdebugçå°æ¹ï¼å ¶å®è¿å¯ä»¥ç´æ¥proä¸å ä¸ä¸è¡æ¥ç¦ç¨æ´ä¸ªé¡¹ç®çqdebugè¾åºã
#ç¦ç¨qdebugæå°è¾åº
DEFINES += QT_NO_DEBUG_OUTPUT
- å¨ä½¿ç¨ QT_NO_DEBUG_OUTPUT å ³é®åç¦ç¨äºæææå°ä¿¡æ¯ä»¥åï¼å¯ä»¥è约ä¸å°çå¼éï¼ææ¶ååæ³å¨ç¦ç¨æå°ä¿¡æ¯åï¼æå°å°æ¹è¿éè¦çå°æå°ä¿¡æ¯ï¼æä¹åå¢ï¼å ¶å® QT_NO_DEBUG_OUTPUT ç¦ç¨ç qdebug çè¾åºï¼Qtè¿æå ¶ä»å ç§æå°ä¿¡æ¯æ¯å¦ qInfoãqWarningãqCriticalï¼è¿äºæ¯ä¸åå½±åçï¼ä¹å°±æ¯è¯´å¨æå°é¨åéè¦æå°çå°æ¹ç¨ qInfo æ¥è¾åºä¿¡æ¯å°±å¥½ãç¹å«æ³¨æï¼qFatal æå°å®ä¿¡æ¯ç¨åºä¼èªå¨ç»æã
qDebug() << "qDebug";
qInfo() << "qInfo";
qWarning() << "qWarning";
qCritical() << "qCritical";
qDebug("qDebug");
qWarning("qWarning");
qCritical("qCritical");
- Qtçproæ件å¯ä»¥æ·»å åç§å¤çæ¥ä½¿å¾é ç½®æ´æ¹ä¾¿ï¼æ¯å¦æå®è¾åºæ件路å¾çï¼è¿æ ·å°±ä¸ä¼å ¨é¨å¨ä¸å ç¼è¯çæç临æ¶æ件ä¸æ¾æ¥æ¾å»ã
#ç¦ç¨qdebugæå°è¾åº
DEFINES += QT_NO_DEBUG_OUTPUT
#èªå®ä¹defineåé å¯ä»¥å¨æ´ä¸ªé¡¹ç®ä¸ä½¿ç¨
#proæ件å¯ä»¥è¿æ ·å¤æ contains(DEFINES, videovlc) {}
#代ç æ件å¯ä»¥è¿æ ·å¤æ #ifdef videovlc
DEFINES += videovlc1 videoffmpeg
#å
³éç¼è¯è¦åæ示 ç¼ä¸è§ä¸ºå
CONFIG += warn_off
#æå®ç¼è¯çæçæ件å°tempç®å½ åé¨å«ç±»åå¨
MOC_DIR = temp/moc
RCC_DIR = temp/rcc
UI_DIR = temp/ui
OBJECTS_DIR = temp/obj
#æå®ç¼è¯çæçå¯æ§è¡æ件å°binç®å½
DESTDIR = bin
- Qt对æä½ç³»ç»å±çæ¶æ¯ä¹åäºå¾å¤çå°è£ ï¼å¯ä»¥ç´æ¥æ¿å°è¿è¡å¤çï¼å¦æéè¦æ¦æªå¤çè¦ç¨å¯¹åºæä½ç³»ç»çAPIæè¡æ¯å¦é¼ æ é®çé©åï¼ï¼æ¯å¦ç³»ç»ä¼ç åå¤éåä¸äºå¤çã
//主çªä½å¤´æ件
protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#ifdef Q_OS_WIN
bool winEvent(MSG *message, long *result);
#endif
//主çªä½å®ç°å½æ°
#ifdef Q_OS_WIN
#include "Windows.h"
#endif
bool frmMain::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (eventType == "windows_generic_MSG") {
#ifdef Q_OS_WIN
MSG *msg = static_cast<MSG *>(message);
//qDebug() << TIMEMS << msg->message;
if (msg->wParam == PBT_APMSUSPEND && msg->message == WM_POWERBROADCAST) {
//ç³»ç»ä¼ç çæ¶åèªå¨æå°åå¯ä»¥è§é¿ç¨åºå¯è½åºç°çé®é¢
this->showMinimized();
} else if (msg->wParam == PBT_APMRESUMEAUTOMATIC) {
//ä¼ç å¤éåèªå¨æå¼
this->showNormal();
}
#endif
} else if (eventType == "NSEvent") {
#ifdef Q_OS_MACOS
#endif
}
return false;
}
#ifdef Q_OS_WIN
bool frmMain::winEvent(MSG *message, long *result)
{
return nativeEvent("windows_generic_MSG", message, result);
}
#endif
- Qtçpro项ç®ç®¡çé ç½®æ件ä¸ä¹å¯æ·»å åç§ç¼è¯é¾æ¥ååçæä½åé ç½®ï¼ä¸»è¦éè¿ QMAKE_POST_LINKåQMAKE_PRE_LINKï¼ä»ä»¬æ¯æçå½æ°ä»¥ååæ³ï¼å¯ä»¥å¨QtCreatorç帮å©ä¸æç´¢ qmake Function Reference æ¥ç详æ 说æã
- QMAKE_PRE_LINK 表示ç¼è¯é¾æ¥åæ§è¡å 容
- QMAKE_POST_LINK 表示ç¼è¯é¾æ¥åæ§è¡å 容
#ä¹å¯ä»¥ç¨éé
符 *.txt / *.* / *
srcFile1 = $$PWD/1.txt
srcFile2 = $$PWD/2.txt
dstPath = $$PWD/../bin
#windowsä¸éè¦è½¬æ¢è·¯å¾ææ å
¶ä»ç³»ç»ä¸éè¦
srcFile1 = $$replace(srcFile1, /, \\);
srcFile2 = $$replace(srcFile2, /, \\);
dstPath = $$replace(dstPath, /, \\);
#ç¼è¯é¾æ¥åæ§è¡æ·è´ å¤ä¸ªæ·è´å¯ä»¥éè¿ && 符å·éå¼
QMAKE_PRE_LINK += copy /Y $$srcFile1 $$dstPath && copy /Y $$srcFile2 $$dstPath
#ç¼è¯é¾æ¥åæ§è¡æ·è´ å¤ä¸ªæ·è´å¯ä»¥éè¿ && 符å·éå¼
QMAKE_POST_LINK += copy /Y $$srcFile1 $$dstPath && copy /Y $$srcFile2 $$dstPath
#ä¸é¢æ¼ç¤ºå è½½pro项ç®çæ¶åå°±æ§è¡æ·è´/å¾å¤æ¶åè¦çå°±æ¯è¿ç§æ¹å¼
srcFile = $$PWD/qrc/*.*
dstPath = $$PWD/bin
srcFile ~= s,/,\\,g
dstPath ~= s,/,\\,g
#windows使ç¨xcopyå½ä»¤/unix使ç¨cpå½ä»¤/unixä¸éè¦è½¬æ¢è·¯å¾
system(xcopy $$srcFile $$dstPath /y /e)
system(cp $$srcFile $$dstPath -f)
system($$QMAKE_COPY $$srcFile $$dstPath)
14ï¼131-140
-
Qtæ°çæ¬å¾å¾ä¼å¸¦æ¥ä¸äºå¤´æ件çæ´æ°ï¼æ¯å¦ä»¥å使ç¨QPainterç»å¶ï¼ä¸éè¦é¢å¤å å«QPainterPath头æ件ï¼è5.15çæ¬å¼å§å°±éè¦æ¾ç¤ºä¸»å¨å¼å ¥#include "qpainterpath.h"æè¡ã
-
Qt6.0åå¸äºï¼æ¯ä¸ªæ¯è¾å¤§çæ¹å¨çæ¬ï¼å¾å¤åºç¡çç±»æè ç»ä»¶é½æ¾å°åç¬çæºç å ä¸ï¼6.0å°6.2ä¹é´ççæ¬éè¦èªè¡å®ç½ä¸è½½å¹¶ç¼è¯ï¼éè¦æå¨ç¼è¯å¹¶éæï¼æ¯å¦QRegExpï¼QTextCodecç±»ï¼éè¦ç¼è¯éæåproæ件 QT += core5compat æè½ç¨ï¼ å ·ä½è¯´æå¨https://doc.qt.io/qt-6/qtcore5-index.htmlã大æ¦ä»Qt6.2å¼å§ï¼åä¸éè¦èªå·±ç¼è¯äºï¼å®è£ çæ¶åå¾écore5compat模åå³å¯ï¼é»è®¤ä¸å¾éã
-
qDebugè¾åºæå°ä¿¡æ¯ï¼é»è®¤ä¼å®æ´æå°è½¬ä¹å符ï¼ä¾å¦ï¼\ " \t \n" çï¼æ以å½ä½ åç°ä½ ææ设置äºè½¬ä¹å符以åæå°ç¡®è¿æ¯è½¬ä¹åçå符ï¼è¿å°±æµé¼äºï¼å ¶å®è¿æ¯qdebug为äºæ¹ä¾¿è°è¯å°åç§å符é½æå°è¾åºãæ å¯å¦è®¤ï¼å¾å¤æ¶åï¼æ们æå ¶å ´å¥ç享åçQt带æ¥çåç§è½®ååç§ä¾¿å©ï¼ä½æ¯å¶å°ï¼ç¨ä¸çæï¼è¿äºä¾¿å©å¯è½ä¹ä¼åä½ ä¸æãè¦åçå°±æ¯æ¦äº®ç¼çï¼æ¶å»è°¨æ ï¼ä¸æ¥ä¸ä¸ªèå°è¸è¸å®å®ç 代ç ã
QString s1 = R"(\:device0)";
//TNNDå±
ç¶è¾åºçæ¯ \\:device0
qDebug() << s1;
//è¿æ¬¡ç»äºæ£ç¡®çè¾åº \:device0
qDebug().noquote() << s1;
- å¾å¤äººæçé®ä¸ºä½qss对æµè§å¨æ§ä»¶ä¸çç½é¡µæ ·å¼æ²¡æ³æ§å¶ï¼å ¶å®ç¨å±è¡æ³æ³ä¹ç¥éï¼é£ç©ææ¯html csså»æ§å¶çï¼åQtä¸æ¯é±å ³ç³»ä¹æ²¡æï¼æ ¹æ¬ç®¡ä¸çï¼å¦ææ³è¦å¯¹æ»å¨æ¡æ ·å¼è®¾ç½®ï¼å¯ä»¥å¨ç½é¡µä»£ç ä¸è®¾ç½®æ ·å¼å°±è¡ã
<style type="text/css">
::-webkit-scrollbar{width:0.8em;}
::-webkit-scrollbar-track{background:rgb(241,241,241);}
::-webkit-scrollbar-thumb{background:rgb(188,188,188);}
</style>
- Qtçinié ç½®æ件é»è®¤ä¸æ¯æç´æ¥è¯»åä¸æï¼éè¦æå¨è®¾ç½®ä¸ç¼ç æ ¼å¼æè¡ï¼å¼ºç建议ç»ä¸ç¨utf-8ç¼ç ï¼å æ¬ä»£ç æ件ã
//设置äºç¼ç 以åé
ç½®æ件å
容为 Company=ä¸æµ·ç©èç½ææ¯ç 究ä¸å¿
//没æ设置ç¼ç åé
ç½®æ件å
容为 Company=\xe4\xb8\x8a\xe6\xb5\xb7\xe7\x89\xa9\xe8\x81\x94\xe7\xbd\x91\xe6\x8a\x80\xe6\x9c\xaf\xe7\xa0\x94\xe7\xa9\xb6\xe4\xb8\xad\xe5\xbf\x83
void App::readConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.setIniCodec("utf-8");
set.beginGroup("AppConfig1");
App::Company = set.value("Company", App::Company).toString();
set.endGroup();
}
void App::writeConfig()
{
QSettings set(App::ConfigFile, QSettings::IniFormat);
set.setIniCodec("utf-8");
set.beginGroup("AppConfig1");
set.setValue("Company", App::Company);
set.endGroup();
}
- ç¨Qtåå®åå¼åé½ä¼éå°æéçé®é¢ï¼æ©æçå®åçæ¬å¯ä»¥ç´æ¥éè¿ AndroidManifest.xml é ç½®æ件æ¥æ·»å éè¦çæéï¼è¿æ ·å¨å®è£ appçæ¶åå°±ä¼æ示该appéè¦åªäºæé让ç¨æ·åæï¼ç°å¨çå®åçæ¬é½æ¹æäºå¨ææéï¼éè¦å¨appè¿è¡çæ¶åå¼¹åºæ示让ç¨æ·ç¡®è®¤æææéï¼Qtè¿åäºè¿ç§çç¥å ç½®äºå¨æç³è¯·æéçæ¹æ³ QtAndroid::requestPermissionsSyncã
//å¨æ设置æé
bool AndroidHelper::checkPermission(const QString &permission)
{
#ifdef Q_OS_ANDROID
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0))
QtAndroid::PermissionResult result = QtAndroid::checkPermission(permission);
if (result == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync(QStringList() << permission);
result = QtAndroid::checkPermission(permission);
if (result == QtAndroid::PermissionResult::Denied) {
return false;
}
}
#else
QFuture<QtAndroidPrivate::PermissionResult> result = QtAndroidPrivate::requestPermission(permission);
if (result.resultAt(0) == QtAndroidPrivate::PermissionResult::Denied) {
return false;
}
#endif
#endif
return true;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//请æ±æé
checkPermission("android.permission.READ_EXTERNAL_STORAGE");
checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
return a.exec();
}
- Qtéè½½qDebugè¾åºèªå®ä¹çä¿¡æ¯ã
struct FunctionInfo {
QString function;
QString name;
QString groupEnabled;
QString action;
QString group;
friend QDebug operator << (QDebug debug, const FunctionInfo &functionInfo) {
QString info = QString("åè½: %1 å称: %2 å¯ç¨: %3 æ¹æ³: %4 åç»: %5")
.arg(functionInfo.function).arg(functionInfo.name).arg(functionInfo.groupEnabled)
.arg(functionInfo.action).arg(functionInfo.group);
debug << info;
return debug;
}
};
- 对é«åå±ä¸å缩æ¾æ¯ä¾çèªéåºå¤çæ¹æ³ã
//æ¹æ³1ï¼å¨mainå½æ°çæåé¢å ä¸ä¸é¢è¿å¥ 5.6çæ¬æå¼å§æè¿ä¸ªå½æ°
#if (QT_VERSION > QT_VERSION_CHECK(5,6,0))
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//å¼å¯é«ç¼©æ¾æ¯æ以åå¾çå¯è½åèè¿è¦å¼å¯ä¸é¢è¿ä¸ªå±æ§
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
//æ¹æ³2ï¼å¨å¯æ§è¡æ件åç®å½ä¸æ°å»ºæ件 qt.conf å¡«å
¥ä¸é¢å
容
[Platforms]
WindowsArguments = dpiawareness=0
//ä¸é¢è¿è¡ç¨æ¥è§£å³Qté«DPIä¸æåæ¾ç¤ºæé¯é½¿çé®é¢
WindowsArguments = fontengine=freetype
//2023-2-2 ç»è¿å»ºæ³¢ï¼ç®ç§°JB大佬ï¼äº²æµä¸¤è¡åå¼å没æææï¼éè¦éå·åå¼
WindowsArguments = dpiawareness=0, fontengine=freetype
//æ¹æ³3ï¼å¨mainå½æ°æåé¢è®¾ç½®Qtå
é¨çç¯å¢åé
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1.5");
//æ¹æ³4ï¼æ°çæ¬çQtæ¯å¦Qt5.14ä¿®æ£äºå¯¹é«åå±çå¤çæ¯æä¸æ¯æ´æ°ç缩æ¾
qputenv("QT_ENABLE_HIGHDPI_SCALING", "1");
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
//ç¦ç¨ç¼©æ¾
//æµè¯åç°AA_Use96Dpiå±æ§å¨Qt5.9以ä¸çæ¬å®å
¨æ£å¸¸ï¼ä»¥ä¸çæ¬æ¯å¦5.7æé¨åæ§ä»¶å¨175%缩æ¾ä¸æ£å¸¸æ¯å¦QTextEditï¼éè¦å¤å±å¥ä¸ªwidgetæè¡ã
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
//Qt6ä¸AA_Use96Dpi没ææå¿
é¡»ä¸é¢æ¹å¼è®¾ç½®å¼ºå¶æå®ç¼©æ¾DPI
qputenv("QT_FONT_DPI", "96");
- QTabWidgeté项å¡æ个èªå¨çææé®åæ¢é项å¡çæºå¶ï¼ææ¶åä¸æ³çå°è¿ä¸ªç¦äººçåæ¢æé®ï¼å¯ä»¥è®¾ç½®usesScrollButtons为åï¼å ¶å®QTabWidgetçusesScrollButtonså±æ§æç»æ¯åºç¨å°QTabWidgetçQTabBar对象ä¸ï¼æ以åªè¦è®¾ç½®å ¨å±çQTabBarçè¿ä¸ªå±æ§å ³éå³å¯ã为å¥è¦è®¾ç½®å ¨å±çå¢ï¼å 为å¦æåªæ¯å¯¹QTabWidget设置äºè¯¥å±æ§ï¼èå¨QMainWindowçªä½ä¸QDockWidgetå并èªå¨å½¢æçé项å¡åªæQTabBar对象导è´ä¾ç¶æ¯æåæ¢æé®ã
//对tabWidget设置æ åæ¢æé®
ui->tabWidget->setUsesScrollButtons(false);
//对tabBar设置æ åæ¢æé®
ui->tabWidget->tabBar()->setUsesScrollButtons(false);
//对æ´ä¸ªç³»ç»çé项å¡è®¾ç½®æ åæ¢æé®
QTabBar{qproperty-usesScrollButtons:false;}
//设置é项å¡èªå¨æ伸 è¿ç©æå±
ç¶ä¹åèªå¨è®¡ç®æ¥è®¾ç½®åæ¥å
ç½®äºååå
QTabBar{qproperty-expanding:false;}
//设置é项å¡å
³éæé®å¯è§
QTabBar{qproperty-tabsClosable:true;}
//è¿æå
¶ä»å±æ§åè§QTabBar头æ件ææå
//ä¾æ§æ¯ä¸è½å¤§æ³ææå¯è§åç±»ç Q_PROPERTY å
å«çå±æ§é½å¯ä»¥è¿æ ·è®¾ç½®
- QMainWindowçåå²çº¿é»è®¤å°ºå¯¸æ¯è¾å¤§ï¼ææ¶åæ³è®¾ç½®å°ä¸ç¹æè ä¸æ³è¦ï¼æå¼å§çæ¶å以为æ¯QSplitterï¼æå°ææåå ç´ æ¾éäºä¹æ²¡æ¾å°å½±åï¼æååç°æ ·å¼è¡¨ä¸æ对åºè®¾ç½®çå 容ã
//ççæ¯å梦ä¹æ²¡æ³å°è¦è¿æ ·è®¾ç½®
QMainWindow::separator{width:1px;height:1px;margin:1px;padding:1px;background:#FF0000;}
15ï¼141-150
- QImageæ¯æxpmå¾æ ï¼æ¥çQtå ç½®çQStyleé£æ ¼ç代ç ä¸å¯ä»¥åç°å¤§éçxpmå¾æ å®ä¹ï¼éè¿ä»£ç çå½¢å¼æ¥äº§çå¾æ ï¼ååå好çé¼ã
static const char * const imgData[] = {
"15 11 6 1",
" c None",
"+ c #979797",
"@ c #C9C9C9",
"$ c #C1C1C1",
"b c None",
"d c None",
" $++++++++$ ",
"$+bbbbbbbb+$ ",
"+b $$ +$ ",
"+b $@ +$ ",
"+b +$",
"+b d+",
"+b d+$",
"+b $$ d+$ ",
"+b $@ d+$ ",
"$+dddddddd+$ ",
" $++++++++$ "};
//è¿æ ·å°±è½ç´æ¥æ¾ç¤ºä¸ä¸ªç®å¤´çå¾å½¢
QImage img(imgData);
QLabel lab;
lab.setPixmap(QPixmap::fromImage(img));
lab.show();
- å¨åé çªä½QDockWidgetåQOpenGLWidgetåæ¶ä½¿ç¨çæ¶åï¼ä»åµå ¥ç¶æåæ¢å°æµ®å¨ç¶ææè æµ®å¨ç¶æåæ¢å°åµå ¥ç¶æï¼QOpenGLWidgetçä¸ä¸æä¼è¢«æ乱导è´ç½å±å¤±æï¼éè¦å¨mainå½æ°ä¸å¼å¤´ä½ç½®è®¾ç½®ä¸å ±äº«OpenGLä¸ä¸æã
int main(int argc, char *argv[])
{
//éè¦è®¾ç½®å
±äº«ä¸ä¸æä¸ç¶åé çªä½ä»æ£å¸¸å°æµ®å¨åQOpenGLWidgetçªä½ä¼å¤±æ
#if (QT_VERSION > QT_VERSION_CHECK(5,4,0))
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif
QApplication a(argc, argv);
...
}
- å ³äºQtä¸æä¹±ç çé®é¢ï¼ä¸ªäººä¹ç¨å¾®æ»ç»äºä¸ç¹ï¼åºè¯¥å¯ä»¥è§£å³99%以ä¸çQtçæ¬çä¹±ç é®é¢ã
- 第ä¸æ¥ï¼ä»£ç æ件éæ©ç¨utf8ç¼ç 带bomã
- 第äºæ¥ï¼å¨æä¸ææ±åç代ç æ件顶é¨å ä¸è¡ï¼ä¸è¬æ¯cppæä»¶ï¼ #pragma execution_character_set("utf-8") å¯ä»¥èèæ¾å¨head.hä¸ï¼ç¶åéè¦çå°æ¹å°±å¼å ¥head头æ件就è¡ï¼èä¸æ¯è¿è¡ä»£ç åçå°å¤é½æ¯ï¼è¿è¡ä»£ç æ¯ä¸ºäºåè¯msvcç¼è¯å¨å½å代ç æ件ç¨utf8å»ç¼è¯ã
- 第ä¸æ¥ï¼mainå½æ°ä¸å å ¥è®¾ç½®ç¼ç ç代ç ï¼ä»¥ä¾¿å ¼å®¹Qt4ï¼å¦æ没æQt4çåºæ¯å¯ä»¥ä¸ç¨ï¼ä»Qt5å¼å§é»è®¤å°±æ¯utf8ç¼ç ã
void QtHelper::setCode()
{
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
QTextCodec *codec = QTextCodec::codecForName("utf-8");
#endif
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
#else
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QTextCodec::setCodecForLocale(codec);
#endif
}
- å ³äºQtä¼å¤çæ¬ï¼è³å°å ç¾ä¸ªï¼é½ä¸å ¼å®¹çé®é¢ï¼å¨ç»è¿åQtä¸å½çææ大ç¥åå ¶ä»å¤§ç¥ï¼Qtéå®æ¹ææ¯äº¤æµç¾¤ï¼å¤´èé£æ´ä»¥åï¼æç»å¾åºä»¥ä¸çç»è®ºã
- Qtå¨äºè¿å¶å ¼å®¹è¿åï¼å·²ç»åäºæ大çåªåï¼éè¿å°åç§ä»£ç ç»èéèï¼Qæé+Dæéæå·§ï¼å°½éä¿æäºæ¥å£çç»ä¸ï¼
- æ¯å¦å ¼å®¹æ主è¦èèç¼è¯å¨çå ç´ ï¼æ¯ç«ä»»ä½Qtçæ¬é½æ¯éè¦éè¿ç¼è¯å¨ç¼è¯æ对åºçäºè¿å¶æ件ï¼ç±ä»è¯´äºç®ãå¦æ两个Qtçæ¬éç¨çç¼è¯å¨çæ¬ä¸æ ·ï¼æ大æ¦çå¯æ§è¡æ件æ¯å ¼å®¹çï¼æ¯å¦ Qt5.10+msvc2015 32 ä½ å Qt5.11+msvc2015 32ä½ ç¼è¯åºæ¥çå¯æ§è¡æ件ï¼é½ç¨Qt5.11çåºæ¯å¯è¡çï¼
- mingwç¼è¯å¨çQtçæ¬ä¹æ¯å¦æ¤ï¼å°±æ¯å 为Qtå®æ¹å®è£ å éæçmingwç¼è¯å¨ä¸ç´å¨æ´æ°ï¼æå°éè¿çæ¬æ²¡ææ´æ°mingwç¼è¯å¨çæ¬é¤å¤ï¼ï¼æ¯å¦5.7ç¨çmingw53ï¼5.12ç¨çmingw73ï¼5.15ç¨çmingw81ï¼å 为带çQtåºä¹æ¯è¿ä¸ªç¼è¯å¨ç¼è¯åºæ¥çï¼æ以导è´çèµ·æ¥å ¨é¨ä¸å ¼å®¹ï¼
- å¦ææ³è¦å®å ¨å ¼å®¹ï¼è¿æä¸ä¸ªæ³¨æè¦ç´ ï¼é£å°±æ¯å¯¹åºä»£ç 使ç¨çç±»ç头æ件æ¥å£æ¯å¦åäºï¼æéçåæçæ¥å£æå°ä¼åï¼ä¸è¬é½æ¯æ°å¢å ï¼æè 大çæ¬æä¼æ¹åï¼æ¯å¦Qt4-Qt5-Qt6è¿ç§è¯å®æ²¡æ³å ¼å®¹çï¼æ¥å£å模åé½åäºï¼
- 大èççæµï¼å¦æQt5.6å°Qt5.15ä½ å ¨é¨ç¨ä¸ç§ç¼è¯å¨æ¯å¦mingw73æè msvc2015éæ°ç¼è¯çæ对åºçQtè¿è¡åºï¼ç¶åå¨æ¤åºç¡ä¸å¼åç¨åºï¼æåçæçå¯æ§è¡æ件ç¨Qt5.15çåºæ¯é½å¯ä»¥çï¼è¿æ ·å°±è½»æ¾è·¨è¶äºå¤ä¸ªçæ¬å ¼å®¹ï¼
- 大èç建议ï¼å¨éè¿çå 个çæ¬ç»ä¸ç¼è¯å¨ï¼æ¯å¦5.6-5.12ä¹é´å°±ç»ä¸ç¨mingw53æè msvc2015,5.12-5.15ç»ä¸ç¨msvc2017ï¼è¦å°é²å ¶ä»ç¼è¯å¨çå¯ä»¥èªè¡æºç ç¼è¯å ¶ä»çæ¬ï¼è¿æ ·æèµ·ç éè¿çä¸å¤§æ®µçæ¬ï¼å¤§æ¦2-3å¹´ççæ¬å¨æï¼é»è®¤å°±å ¼å®¹äºã
- æ¬äººæµè¯çæ¯widgeté¨åï¼qmlæªåæµè¯ï¼ä¸æ¸ æ¥æ¯å¦æºå¶ä¸æ ·ï¼
- éè¿é ·ç 大å¥ï¼Qtå¼åè 交æµç¾¤ï¼çæç¹ï¼å°ä»å¤©æç¥éï¼Qtè®¾ç½®æ ·å¼è¡¨æ¯æç´æ¥ä¼ å ¥æ ·å¼è¡¨æ件路å¾ï¼äº²æµ4.7å°5.15ä»»æçæ¬ï¼éè¿æ¥ç对åºå½æ°çæºç å¯ä»¥çå°å é¨ä¼æ£æ¥æ¯å¦æ¯ 'file:///' å¼å¤´ï¼æ¯çè¯åèªå¨è¯»åæ ·å¼è¡¨æ件è¿è¡è®¾ç½®ï¼æ éæå¨è¯»åã
//以åé½æ¯ä¸é¢çæ¹æ³
QFile file(":/qss/psblack.css");
if (file.open(QFile::ReadOnly)) {
QString qss = QLatin1String(file.readAll());
qApp->setStyleSheet(qss);
file.close();
}
//å
¶å®ä¸è¡ä»£ç å°±è¡
qApp->setStyleSheet("file:///:/qss/psblack.css");
//ç¹å«è¯´æï¼åªæ¯æqApp->setStyleSheet ä¸æ¯æå
¶ä»æ¯å¦widget->setStyleSheet
- Qtä¸èªå¸¦çå¾å¤æ§ä»¶ï¼å ¶å®é½æ¯ç±ä¸å åºç¡æ§ä»¶ï¼QLabelãQPushButtonçï¼ç»æçï¼æ¯å¦æ¥åé¢æ¿ QCalendarWidget å°±æ¯ QToolButton+QSpinBox+QTableView çç»æï¼å¦ç¨ findChildren å¯ä»¥æ¿å°ç¶ç±»å¯¹åºçåæ§ä»¶éåï¼å¯ä»¥ç´æ¥å¯¹å°è£ çæ§ä»¶ä¸çåæ§ä»¶è¿è¡æ ·å¼ç设置ï¼å ¶ä»åæ°ç设置æ¯å¦è®¾ç½®ä¸æææ¬ï¼é»è®¤å¯è½æ¯è±æï¼çã
//æå°å类类åéå
void printObjectChild(const QObject *obj, int spaceCount)
{
qDebug() << QString("%1%2 : %3")
.arg("", spaceCount)
.arg(obj->metaObject()->className())
.arg(obj->objectName());
QObjectList childs = obj->children();
foreach (QObject *child, childs) {
printObjectChild(child, spaceCount + 2);
}
}
//æ¿å°å¯¹è¯æ¡è¿è¡è®¾ç½®åç¾å
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
QLabel *lookinLabel = fileDialog->findChild<QLabel*>("lookInLabel");
lookinLabel->setText(QString::fromLocal8Bit("æ件ç®å½ï¼"));
lookinLabel->setStyleSheet("color:red;");
//设置æ¥ææ¡é»è®¤å¼ä¸ºç©º
QLineEdit *edit = ui->dateEdit->findChild<QLineEdit *>("qt_spinbox_lineedit");
if (!edit->text().isEmpty()) {
edit->clear();
}
- Qtå ç½®äºåç§å¯¹è¯æ¡ï¼æ¯å¦æ件对è¯æ¡-QFileDialog ï¼é¢è²å¯¹è¯æ¡-QColorDialog ï¼é»è®¤é½ä¼éç¨ç³»ç»ç对è¯æ¡é£æ ¼æ ·å¼ï¼è¿æ ·å¯ä»¥ä¿æåç³»ç»ä¸è´ï¼å¦æä¸éè¦çè¯å¯ä»¥åæ¶è¯¥ç¹æ§ï¼åæ¶ä»¥åä¼éç¨Qtèªèº«ç对è¯æ¡ï¼è¿æ ·æè½è¿è¡ç¾ååå ¶ä»å¤çã
QFileDialog *fileDialog = new QFileDialog(this);
//ä¸è®¾ç½®æ¤å±æ§æ ¹æ¬æ¥æ¾ä¸å°ä»»ä½åå
ç´ ,å 为é»è®¤éç¨çç³»ç»å¯¹è¯æ¡
fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
qDebug() << fileDialog->findChildren<QLabel *>();
//æå°è¾åº QLabel(0x17e2ff68, name="lookInLabel"), QLabel(0x17e35f88, name="fileNameLabel"), QLabel(0x17e35e68, name="fileTypeLabel")
- QtCreatoréæå¼åç¯å¢ï¼ä¹å ç½®äºå¯¹å¿«éæ·»å 注éçæ¯æï¼æ¯å¦æ常ç¨çå¨å¤´æ件å¼å¤´æ·»å ä¸å¤§æ®µéç¨æ¨¡æ¿ç注éï¼æ 注æ件å建è ãæ¶é´çä¿¡æ¯ã
- èå->å·¥å ·->é项->ææ¬ç¼è¾å¨->å³ä¾§tab页é¢ç段(snippets)ï¼
- ç»éæ©C++, å¯ä»¥çå°è¿éé¢å·²ç»å ç½®äºä¸å°å®ä¹æ¯å¦foreachï¼å¯ä»¥ä¾è«è¦ç»ç¢ï¼
- æ·»å ä¸ä¸ªç段, æ¯å¦ååæ¯fun, 触åç§ç±»æ¯è¿ä¸ªç段çç®åæè¿°ï¼
- å½æ们å¨ä»£ç æ件ä¸é®å ¥funæ¶, ä¼èªå¨å¼¹åºæºè½æé, éæ©æ们ç代ç ç段å车, èªå¨å¡«å 代ç ï¼
- ætabå¯ä»¥å¨åéé´åæ¢, è¾å ¥å®æåå车, å®æç¼è¾ï¼
/**
* @brief $name$
* @param $param$
* @author feiyangqingyun
* @date $date$
*/
$ret$ $name$($param$)
{
$$
}
- Qt5æ¶ä»£å¯¹ä¿¡å·æ§½è¿è¡æºå¶æ®è¯´æäºå¾å¤§çæ¹è¿ã
- å¨Qt5ä¹åï¼connectä¸è¬é½åªè½è¿ä¹åconnect(sender, SIGNAL(signalFunc()), receiver, SLOT(receiveFunc()))ï¼å°±æ¯è¯´å¨connectçæ¶åï¼å¿ é¡»æä¿¡å·ç¨å®SIGNALå 裹起æ¥ï¼æ槽å½æ°ç¨å®SLOTå 裹起æ¥ï¼è¿æ ·æè½è¢«QtçMocæºå¶è¯å«ï¼
- å¨ç¼è¯çæ¶åå³ä½¿ä¿¡å·æ槽ä¸åå¨æè åæ°ä¸æ£ç¡®ä¹ä¸ä¼æ¥éï¼ä½æ¯å¨æ§è¡çæ¶åæ æï¼ä¼æå°æ示ï¼å¯¹äºC++è¿ç§éæè¯è¨æ¥è¯´ï¼è¿æ¯ä¸å好çï¼ä¸å©äºè°è¯ï¼
- ä½æ¯Qt5ä¹åæ´å æ¨è"åå°åçåæ³"ï¼éç¨è¿ç§åæ³ï¼å¦æç¼è¯çæ¶åä¿¡å·æ槽ä¸åå¨æ¯æ æ³ç¼è¯éè¿çï¼ç¸å½äºç¼è¯æ¶æ£æ¥ï¼ä¸å®¹æåºéï¼
- å¦æ没æåå²éçé®é¢éè¦å ¼å®¹Qt4çè¯ï¼è¿æ¯æ¨èç¨æ°åæ³ï¼æç±»åæ£æ¥æ´ä¸¥æ ¼ï¼èä¸æ¯æçåæ³å¤æ ·é常çµæ´»ï¼
- ä¸äºç®åçå¤çé»è¾å¼ºçæ¨èç´æ¥lambda表达å¼ç´æ¥å¤çå®ï¼
class MainWindow : public QMainWindow
{
Q_OBJECT
public: MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private:
void test_fun();
private slots:
void test_slot();
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//æ©æåæ³,éç¨Qtææçæ¬,åªæ¯æå®ä¹äºslotså
³é®åçå½æ°
//connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(test_fun()));
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(test_slot()));
//æ°åæ³,æ¯æQt5ååæææçæ¬,æ¯æææå½æ°,æ éå®ä¹slotså
³é®åä¹è¡
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::test_fun);
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::test_slot);
//å¦ç±»åæ³,æ¯ælambda表达å¼,ç´æ¥æ§è¡ä»£ç
connect(ui->pushButton, &QPushButton::clicked, [this] {test_fun();});
connect(ui->pushButton, &QPushButton::clicked, [this] {
qDebug() << "hello lambda";
});
//lambda带åæ°
connect(ui->pushButton, &QPushButton::clicked, [&] (bool isCheck) {
qDebug() << "hello lambda" << isCheck;
});
//头æ件 signals:void sig_test(int i);
connect(this, &MainWindow::sig_test, [] (int i) {
qDebug() << "hello lambda" << i;
});
emit sig_test(5);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::test_fun()
{
qDebug() << "test_fun";
}
void MainWindow::test_slot()
{
qDebug() << "test_slot";
}
- Qtæ ·å¼è¡¨æå¤ç§è¿è¡æºå¶ï¼ä¸»è¦æ¯èèå°åç§éæ±åºæ¯ï¼ç»§æ¿èªQWidgetçç±»åqAppç±»é½æ¯æsetStyleSheetæ¹æ³ï¼è¿å¯ä»¥ç»ä¸å°æ ·å¼è¡¨æ¾å¨æ件ï¼æè å°æ ·å¼æ件å å ¥å°èµæºæ件ã
- ææ°ï¼qsså 容åå¾å°å¤é½æ¯ï¼åªééè¦å°±åå¨åªéï¼åç§æ§ä»¶è°ç¨ setStyleSheetæ¹æ³ä¼ å ¥æ ·å¼è¡¨å 容ï¼æè ç´æ¥å¯¹åºæ§ä»¶é¼ æ å³é®å¼¹åºèåéæ©æ¹åæ ·å¼è¡¨å¡«å ¥å 容ï¼
- æè ï¼qsså 容æ¾å¨æ件ï¼è¯»åæ件å å®¹è®¾ç½®æ ·å¼è¡¨ï¼ç¨åºåå¸çæ¶å带ä¸qssæ件ï¼
- æå¸ï¼qssæ件ä½ä¸ºèµæºæ件æ¾å°qrcæ件ï¼ç´æ¥ç¼è¯å°å¯æ§è¡æ件ä¸ï¼é²æ¢ç¯¡æ¹ï¼
- æçµï¼å¨qssæ件ä¸èªå®ä¹ä¸äºæ å¿å å½åé使ç¨ï¼è¯»å以åæ¿æ¢å¯¹åºçåé为é¢è²å¼ï¼ç±»ä¼¼å¨ææ¢è¤ï¼
- æçï¼æ¾å¨æ件容æ被篡æ¹ï¼éæå°å¯æ§è¡æ件ä¸å¤çµæ´»ï¼ä¸æ¦æ ·å¼è¡¨æ´æ°éè¦éæ°ç¼è¯æ件ï¼å¦ä½åå°æ¢è½åªæ´æ°æ ·å¼è¡¨æ件ï¼åä¸éè¦éæ°ç¼è¯å¯æ§è¡æ件ï¼åè½é²æ¢è¢«ç¯¡æ¹ï¼éç¨rccå½ä»¤å°èµæºæ件ç¼è¯çæäºè¿å¶ï¼åªéè¦æ¿æ¢è¯¥äºè¿å¶æ件å³å¯ï¼
- æçï¼ç»§æ¿qstyleç±»èªå·±å®ç°å®ææææ ·å¼æ¥å£ï¼ç»ä¸æ´ä½é£æ ¼ï¼å¤§åé¼é¼çUOSç³»ç»é»è®¤è§åå°±æ¯å¦æ¤ï¼ä¸å 许ç¨æ ·å¼è¡¨ï¼å ¨é¨painterç»å¶ï¼
16ï¼151-160
- å½Qtä¸ç¼è¯èµæºæ件太大æ¶ï¼æçå¾ä½ï¼æè éè¦ä¿®æ¹èµæºæ件ä¸çæ件æ¯å¦å¾çãæ ·å¼è¡¨çï¼éè¦éæ°ç¼è¯å¯æ§è¡æ件ï¼è¿æ ·å¾ä¸å好ï¼å½ç¶Qté½ç»æ们èè好äºçç¥ï¼æ¤æ¶å¯ä»¥å°èµæºæ件转å为äºè¿å¶çrccæ件ï¼è¿æ ·å°±å°èµæºæ件åç¬åºæ¥äºï¼å¯å¨éè¦çæ¶åå¨æå è½½ã
//Qtä¸ä½¿ç¨äºè¿å¶èµæºæ件æ¹æ³å¦ä¸
//å°qrcç¼è¯ä¸ºäºè¿å¶æ件rccï¼å¨æ§å¶å°æ§è¡ä¸åå½ä»¤
rcc -binary main.qrc -o main.rcc
//å¨åºç¨ç¨åºä¸æ³¨åèµæºï¼ä¸è¬å¨mainå½æ°å¯å¨å就注å
QResource::registerResource(qApp->applicationDirPath() + "/main.rcc");
- å ³äºè®¾ç½®åä½ï¼å¤§æ¦é½ä¼ç»åä¸ä¸ªè¯¯åºï¼æ¬æ¥æ¯æç®è®¾ç½®æ´ä¸ªçªä½å æ¬åæ§ä»¶çåä½å¤§å°çï¼ç»æåç°åªæ主çªä½èªå·±åºç¨äºåä½èåæ§ä»¶æ²¡æã
//å设çªä½ä¸æåæ§ä»¶ï¼é»è®¤åä½12pxï¼ç¶ç±»ç±»åæ¯QWidgetï¼ç¶ç±»ç±»åæ¯Widget
//ä¸é¢å ç§æ¹æ³åªä¼è®¾ç½®ä¸»çªä½çåä½ï¼åæ§ä»¶ä¸ä¼åºç¨ï¼éè¦æ个è°ç¨setFont
QFont font;
font.setPixelSize(20);
this->setFont(font);
this->setStyleSheet("{font:26px;}");
this->setStyleSheet("QWidget{font:26px;}");
this->setStyleSheet("Widget{font:26px;}");
//ä¸é¢ææ¯éè¿æ ·å¼è¡¨è®¾ç½®æ´ä¸ªæ§ä»¶+åæ§ä»¶çåä½
this->setStyleSheet("font:26px;");
this->setStyleSheet("*{font:26px;}");
this->setStyleSheet("QWidget>*{font:26px;}");
this->setStyleSheet("Widget>*{font:26px;}");
//ä¸é¢è®¾ç½®å
¨å±åä½
qApp->setFont(font);
- Qtä¸å°è£ çQImageå¼å¸¸ç强大ï¼æä¾äºåç§å¾çæ ¼å¼ç转æ¢ï¼è¿å¯ä»¥å¯¹æ¯ä¸ªåç´ çé¢è²å¼è¿è¡æ¿æ¢ï¼ææ¶åæ们éè¦å°åè²çå¾çæ¢æå¦å¤ä¸ç§é¢è²ï¼è¦æ³¨æçæ¯å¦æ带æéæå¼çé¢è²éè¦è¿è¡æ ¼å¼è½¬åï¼æ¯å¦è½¬æFormat_ARGB32æè Format_RGBA8888ã
//pixel å½æ°è·ååç´ ç¹çé¢è² setPixel å½æ°è®¾ç½®åç´ ç¹çé¢è² æ¤å½æ°ä»»æQtçæ¬é½æ
//pixelColor å½æ°è·ååç´ ç¹çé¢è² setPixelColor å½æ°è®¾ç½®åç´ ç¹çé¢è² æ¤å½æ°Qt5.6以åææ
//pixelå½æ°ååºæ¥çæ¯QRgbæ ¼å¼éè¦ç¨ qRed qGreen qBlue qAlpha è¿è¡è½¬æ¢
QImage image("1.png");
image = image.convertToFormat(QImage::Format_ARGB32);
int width = image.width();
int height = image.height();
//éåå¾åçæ¯ä¸ä¸ªåç´
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
QString name = image.pixelColor(x, y).name();
//å°ç½è²ä»¥å¤çé¢è²å
¨é¨æ¿æ¢æ红è²
if (name != "#ffffff") {
image.setPixelColor(x, y, Qt::red);
}
}
}
//ä¿åæ件
image.save("2.png");
- å¨æ°æ®åºç¸å ³çåºç¨ä¸ï¼å¦æä» ä» æ¯åæºçæ¬ï¼æ²¡æç¹å«çéè¦ï¼æ¯å¦é¢å¯¼æå®ï¼æè éè¦è¿ç¨åæ¾æ°æ®ï¼ï¼å¼ºç建议使ç¨sqliteæ°æ®åºï¼è¿æ¯æ¬äººç»è¿æ æ°æ¬¡ç对æ¯æµè¯åN个åä¸é¡¹ç®åºç¨å¾åºçç»è®ºã
- Qt天çå ç½®äºsqliteæ°æ®åºï¼åªéè¦åå¸çæ¶å带ä¸æ件就è¡ï¼å¯ä»¥çå°æ件å¨æåºæ件æ¯å ¶ä»å ç§é½è¦å¤§ï¼é£æ¯å 为ç´æ¥å°æ°æ®åºçæºç é½ç¼è¯è¿å»äºï¼èå ¶ä»åªç¼è¯äºä¸é´é信交äºçæ件æºç ï¼ï¼å ¶ä»æ°æ®åºè¦ä¹è¿è¦å¸¦ä¸å¨æåºï¼è¦ä¹è¿éè¦å建æ°æ®æºï¼
- é度ä¸ï¼ç»å¯¹æ ä¸ä¼¦æ¯çåºç±»æèï¼åæ ·çæ°æ®åºç»æï¼è¡¨ç»æãç´¢å¼çå®å ¨ä¸è´ï¼ï¼æ¥è¯¢é度åæ¹éæ´æ°é度ãæ°æ®åºäºå¡çï¼é度é½æ¯å ¶ä»å ç§çè³å°3å以ä¸ï¼èä¸éçæ°æ®éçå¢å¤§å¯¹æ¯è¶åææ¾ï¼
- å åä¸çæ°æ®éå®å ¨æ²¡é®é¢ï¼èä¸é度åæ§è½é½è¿å¯ä»¥ï¼ä¸è¦ä»¥è®¹ä¼ 讹ç½ä¸é¨åè鸡说çä¸æ¯æç¾ä¸ä»¥ä¸çæ°æ®éï¼æ¬äººäº²æµäº¿çº§å«ï¼æ°æ®é建议åä¸çº§å«ä»¥ä¸ï¼çé注ææ°æ®åºè¡¨åç´¢å¼ç设计ï¼
- å ¶ä»æ°æ®åºè¿è¦æ³¨æçæ¬çåºå«ï¼ODBCæ°æ®æºå½¢å¼è¿å®¹æåºéåæ§è¡å¤±è´¥ï¼
- sqliteæ°æ®åºä¹æå 个é大缺ç¹ï¼ä¸æ¯æå å¯ï¼ä¸æ¯æç½ç»è®¿é®ï¼ä¸æ¯æé¨åæ°æ®åºé«çº§ç¹æ§ï¼ä¸æ¯ææµ·éæ°æ®ï¼äº¿çº§å«ä»¥ä¸ï¼ï¼ä½æ¯å¯¹äºç»å¤§é¨åQt项ç®è¿æ¯è¶³å¤ï¼
- æ°æ®åºæ¯æå好度大è´æ¯ sqlite > postgresql > mysql > odbc ;
- å¦æéç¨çodbcæ°æ®æºæ¨¡å¼è¿æ¥æ°æ®åºï¼åªéè¦è®¾ç½®æ°æ®åºå称为对åºæ°å»ºçæ°æ®æºååï¼ç¶å设置ç¨æ·ååå¯ç å°±è¡ï¼ä¸éè¦è®¾ç½®ä¸»æºå称å端å£ï¼å 为æ°æ®æºé£è¾¹å·²ç»è®¾ç½®è¿çï¼è¿éåªéè¦å次éªè¯ç¨æ·ä¿¡æ¯å°±è¡ã
- ODBCæ°æ®æºå32/64ä½ä¹åï¼å¨æ°æ®æºç®¡çå¨ä¸ï¼å¦ææ·»å çæ°æ®æºå¯¹åºå¹³å°æ¾ç¤ºçåªæ32æè åªæ64ä½ï¼é£ä½ çQtç¨åºä¹åªè½æ¯å¯¹åºä½æ°çæè½è¿æ¥æåãå¦ææ¾ç¤ºçæ¯64ä½ï¼ä½ ç¨32ä½çç¨åºå»è¿æ¥ä¼å¤±è´¥ã
- 32ä½çQtç¨åºï¼å¸¦å¯¹åº32ä½çlibmysqlå¨æåºï¼å¯ä»¥è®¿é®32/64ä½çmysqlæ°æ®åºï¼64ä½çä¹æ¯ä¸æ ·å¯ä»¥è®¿é®32/64ä½çmysqlæ°æ®åºï¼åªéè¦å¸¦ä¸å¯¹åºä½æ°çå¨æåºå°±è¡ãæ¥çmysqlæ¯32ä½è¿æ¯64ä½å½ä»¤ mysql.exe -Vã
- å¨mysql驱å¨å¯ç¨ä¸æ£å¸¸çæ åµä¸ï¼å¦æè¿æ¯æ示Driver not loaded Driver not loadedï¼åå¾å¯è½æ¯æ·è´çlibmysqlå¨æåºçæ¬ä¸å¯¹æè ä½æ°ä¸å¯¹å¯¼è´çã
- 以ä¸é½æ¯å¨Qtç¯å¢ä¸ä¸ªäººæµè¯å¾åºçç»è®ºï¼ç»ææªå¿ æ£ç¡®ï¼ä½ä¸ºåèå³å¯ï¼å ¶ä»ç¼ç¨ç¯å¢æ¯å¦C#ãJAVA请忽ç¥ï¼ä¹è®¸å·®å«å¯è½å¨ä¸é´éä¿¡çæçé æçï¼
- Qt5.10以åæä¾äºæ°çç±» QRandomGenerator QRandomGenerator64 管çéæºæ°ï¼ä½¿ç¨æ´æ¹ä¾¿ï¼å°¤å ¶æ¯åæ个åºé´çéæºæ°ã
//æ©æå¤çåæ³ å
åå§åéæºæ°ç§åç¶ååéæºæ°
qsrand(QTime::currentTime().msec());
//å 0-10 ä¹é´çéæºæ°
qrand() % 10;
//å 0-1 ä¹é´çæµ®ç¹æ°
qrand() / double(RAND_MAX);
//æ°çå¤çåæ³ æ¯æ5.10以åçææçæ¬å
æ¬qt6
QRandomGenerator::global()->bounded(10); //çæä¸ä¸ª0å10ä¹é´çæ´æ°
QRandomGenerator::global()->bounded(10.123); //çæä¸ä¸ª0å10.123ä¹é´çæµ®ç¹æ°
QRandomGenerator::global()->bounded(10, 15); //çæä¸ä¸ª10å15ä¹é´çæ´æ°
//å
¼å®¹qt4-qt6å以åææçæ¬çæ¹æ³ å°±æ¯ç¨æ åc++çéæºæ°å½æ°
srand(QTime::currentTime().msec());
rand() % 10;
rand() / double(RAND_MAX);
//éç¨å
¬å¼ aæ¯èµ·å§å¼,næ¯æ´æ°çèå´
int value = a + rand() % n;
//(min, max)çéæºæ°
int value = min + 1 + (rand() % (max - min - 1));
//(min, max]çéæºæ°
int value = min + 1 + (rand() % (max - min + 0));
//[min, max)çéæºæ°
int value = min + 0 + (rand() % (max - min + 0));
//[min, max]çéæºæ°
int value = min + 0 + (rand() % (max - min + 1));
//å¦æå¨çº¿ç¨ä¸åéæºæ°ï¼çº¿ç¨å¯å¨çæ¶é´å ä¹ä¸æ ·ï¼å¾å¯è½åºç°åå°çéæºæ°ä¸æ ·çé®é¢ï¼å°±ç®è®¾ç½®éæºæ°ä¸ºå½åæ¶é´å¥çä¹æ²¡ç¨ï¼çµè太快å¾å¯è½è¿æ¯ä¸æ ·çæ¶é´ï¼åä¸ä¸ªæ¯«ç§ã
//åå·§åæ³å°±æ¯å¨runå½æ°ä¹åæåé¢å°å½å线ç¨çidä½ä¸ºç§å设置ãæ¶é´ä¸å¯é ï¼çº¿ç¨çidææ¯å¯ä¸çã
//åè®° void * 转æ¢å°æ°å¼å¿
é¡»ç¨ long longï¼å¨32ä½æ¯å¯ä»¥intä½æ¯å¨64ä½å¿
é¡»longï¼ç¡®ä¿ä¸ä¸ç´æ¥ç¨quint64æ大
srand((long long)currentThreadId());
qrand((long long)currentThreadId());
- QtçUIçé¢å¨resize以åæ个BUGï¼æ¬åæ ·å¼æ²¡æåæ¶æï¼éè¦ä¸»å¨æ¨¡æé¼ æ å¨ä¸ä¸ã
void frmMain::on_btnMenu_Max_clicked()
{
......
//æ大å以åæ个BUG,æ¬åæ ·å¼æ²¡æåæ¶æ,éè¦ä¸»å¨æ¨¡æé¼ æ å¨ä¸ä¸
QEvent event(QEvent::Leave);
QApplication::sendEvent(ui->btnMenu_Max, &event);
}
- 项ç®ä¸å¯ç¨c++11è¯æ³æ¯æã
greaterThan(QT_MAJOR_VERSION, 4): CONFIG += c++11
lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11
- Qtçææ¬æ§ä»¶æ¯å¦QTextEdité»è®¤å 载大ææ¬æ¯å¦10MBçææ¬ï¼å¾å®¹æå¡æ»çè³å´©æºï¼é£æ¯å 为é»è®¤ä¸ä¸ªå±æ§å¼å¯äºï¼éè¦å±è½æ就好å¾å¤ã
ui->textEdit->setUndoRedoEnabled(false);
- å ¶ä»å ç¹å¸¸è§å°ç»éªï¼æ¬äººå¨è¿å 个å°æ¹æè·¤è¿å¾å¤æ¬¡ã
- æè¿åå¼çå½æ°ï¼ä¸å®è¦ä¸»å¨returnè¿åå¼ï¼æé¨åç¼è¯å¨å¨æ²¡æè¿åå¼çæ åµä¸ä¹è½æ£å¸¸ç¼è¯éè¿ï¼ä½æ¯è¿è¡çæ¶åä¼åºé®é¢ï¼å¾ä¸å°æ³è¦çç»æï¼å 为没æreturn对åºçå¼ã
- å®ä¹çå±é¨åéï¼ä¸»å¨ç»å®ä¸ªåå§å¼ï¼æ¯ä¸ªå¿ é¡»å »æçå¥½ä¹ æ¯ï¼ä¸ç¶ç¼è¯å¨ç»çåå§å¼å¾å¯è½ä¸æ¯ä½ æ³è¦çï¼æ¯å¦intåéé»è®¤0ï¼ææ¶åéæºåæä¸ä¸ªå¾å¤§çæ°å¼ï¼boolåéçåå§å¼ä¸åç¼è¯å¨ä¸åå¼ï¼æäºæ¯trueæäºæ¯falseï¼ä¸»å¨ç»ä¸ä¸ªåå§å¼æ´å¯é ã
- æäºå½æ°åæ°å¾å¤ï¼èä¸åæå¯è½è¿ä¼ä¿®æ¹åå¢å ï¼è¿å°±å¯¼è´äºæºå¤´ä¿®æ¹ä»¥åï¼å ³èä¿¡å·æ§½çå°æ¹ä¹è¦ä¿®æ¹ï¼åæ°ç±»ååä½ç½®å¿ é¡»ä¿æå®å ¨ä¸è´ï¼å¯¹åºæ§½å½æ°å¤çä¹è¦ä¿®æ¹çï¼æ¹å¨çå·¥ä½éé常大èä¸æä¸å好ï¼æ以对äºéåºå®åæ°çå½æ°ï¼å»ºè®®ç¨ç»æä½ï¼è¿æ ·é常容æå¢å å ¶ä»çåæ°ï¼èä¸ä¸ç¨ä¿®æ¹ä¿¡å·æ§½å ³èåä¿¡å·æ§½å½æ°å®ä¹çï¼æ¯å¦å¦çä¿¡æ¯è¡¨ãååä¿¡æ¯è¡¨ä½ä¸ºåæ°ä¼ è¾ï¼æä½³æ¹æ¡å°±æ¯ç»æä½ã
- QTabWidgeté项å¡æ§ä»¶ï¼çæçtabbaré项å¡å®½åº¦æ¯æç §ææ¬èªå¨è®¾ç½®çï¼ææ¬è¶é¿é项å¡ç宽度è¶å¤§ï¼å¾å¤æ¶åï¼æ们éè¦çæ¯ä¸æ ·ç宽度æè çåå¡«å ï¼
//æ¹æ³1ï¼åç¬¦ä¸²ç©ºæ ¼å¡«å
ui->tabWidget->addTab(httpClient1, "æµ è¯");
ui->tabWidget->addTab(httpClient1, "人å管ç");
ui->tabWidget->addTab(httpClient1, "ç³»ç»è®¾ç½®");
//æ¹æ³2ï¼è¯å«å°ºå¯¸æ¹åäºä»¶èªå¨è®¾ç½®æå°å®½åº¦
void MainWindow::resizeEvent(QResizeEvent *e)
{
int count = ui->tabWidget->tabBar()->count();
int width = this->width() - 30;
QString qss = QString("QTabBar::tab{min-width:%1px;}").arg(width / count);
this->setStyleSheet(qss);
}
//æ¹æ³3ï¼è®¾ç½®å
¨å±æ ·å¼ï¼ä¸åé项å¡ä¸ªæ°ç设置ä¸åç宽度
QStringList list;
list << QString("QTabWidget[tabCount=\"2\"]>QTabBar::tab{min-width:%1px;}").arg(100);
list << QString("QTabWidget[tabCount=\"3\"]>QTabBar::tab{min-width:%1px;}").arg(70);
qApp->setStyleSheet(list.join(""));
//设置äºtabCountå¼±å±æ§èªå¨å»æ¾å¯¹åºç宽度设置
ui->tabWidget->setProperty("tabCount", 2);
ui->tabWidget->setProperty("tabCount", 3);
//æ¹æ³4ï¼å¼ºçæ¨è-ã使ç¨å
ç½®çæ¹æ³ setExpanding setDocumentMode 两个å±æ§é½å¿
须设置
//Qt4çtabBar()æ¯propectedçï¼æ以建议è¿æ¯éè¿æ ·å¼è¡¨è®¾ç½®
ui->tabWidget->tabBar()->setDocumentMode(true);
ui->tabWidget->tabBar()->setExpanding(true);
//æ ·å¼è¡¨ä¸æ¥å°ä½ä¸ç¨æ¯ä¸ªé½åç¬è®¾ç½®
QString("QTabBar{qproperty-usesScrollButtons:false;qproperty-documentMode:true;qproperty-expanding:true;}");
//å¨5.9以åå¼å¯è¿ä¸ªè®¾ç½®åï¼è²ä¼¼é项å¡ä¸ªæ°æç
§çå®ä¸ªæ°+1计ç®å®½åº¦ï¼ä¹å°±æ¯æ°¸è¿ä¼ç空ä¸ä¸ªtabçå ä½ã
//5.9以åè²ä¼¼ä¿®å¤äºè¿ä¸ªBUGï¼æç
§çæ³ä¸çæ伸填å
çå设置tabç宽度ã
17ï¼161-170
-
ç»å¸¸æ人说Qtåå¾ï¼è¯´ç¨Qtå¨1毫ç§ç»å¶å å个æ°æ®ç¹å¡æå±ãå ¶å®æ¾ç¤ºå¨æé«å·æ°é¢çä¸è¬æ60帧ï¼1毫ç§å°±ç»å¶ä¸æ¬¡ææä¹åï¼ä¸ä» æ¾ç¤ºå¨æ²¡å·æ°è¿æ¥ï¼äººèç¼ä¹çä¸è¿æ¥ï¼æ人å¯è½åè¦æ¬æ 说è¿æ¯èæ¿è¦æ±çï¼æ¾ç¤ºå½æ¾ç¤ºï¼è³äºäººçä¸çé£æ¯å¦å¤ä¸åäºï¼ææ³è¯´çæ¯æ¾ç¤ºä¸å°±æ¯ç»äººççåï¼ç»ç¨åºçå¯ä»¥ç´æ¥åå°ç»å¶å¾ç让ç¨åºè¯å«åæ²¡å¿ è¦æ¾ç¤ºçï¼ï¼ç¨åºä¸è¦åçåºè¯¥æ¯å°½ééä½ç¨åºçç»å¶å·æ°é¢çå°æ¾ç¤ºå¨çé¢çï¼å ¶å®ä¸ç§é30帧é½è¶³å¤ï¼ï¼ä¸æ¬¡æå¤ä¸ç¹çæ°æ®ä¸æ¬¡æ§ç»å¶ï¼æ°æ®éå¾å¤§è¿å¯ä»¥èèééæ ·ï¼æ¯å¦å¹³åå¼æ³çï¼æ¯ç«è¦èèæ¾ç¤ºå¨çå辨çå°±é£ä¹å¤§ï¼æ个å åä¸çæ°æ®ç¹æ¤ä¸å没å¥ææï¼å¯ä»¥å°ä¸æ´ååºåå çæ°æ®ç¹æ¢æä¸ä¸ªç¹ï¼ï¼èä¸æ¯ç»å¶å¤æ¬¡ï¼å°½ç®¡ä¸¤ç§åæ³é½å¯ä»¥å°æ¶å°çæ°æ®ç»å¶å®æï¼ä½æ¯æçç¸å·®çä¸æ¯ä¸ç¹ç¹ï¼ä¿¡å·ä¹æ¯å¦æ¤ï¼ä¸å»ºè®®å¤ªé¢ç¹çåéä¿¡å·ï¼Qtå é¨1ç§éå¤çä¿¡å·ç个æ°ä¹æ¯æéå¶çï¼å¤ªé¢ç¹é«å¹¶åçä¿¡å·ï¼å¾å¯è½ä¼ä¸¢å¤±æè å并ä¸é¨åï¼æ¯å¦ç½ç»è¯·æ±æ¥æ¶å°çå¦çä¿¡æ¯è¡¨ï¼åºè¯¥æ¯å¨è¯¥åºçæ°æ®å çææå¦çä¿¡æ¯è§£æå®ä¸æ¬¡æ§åéï¼èä¸æ¯è§£æä¸æ¡åéä¸æ¡ã
-
Qtæä¾äºNç§çªä½å±æ§æ¯å¦æ è¾¹æ¡å±æ§FramelessWindowHintãä¸å¨ä»»å¡æ æ¾ç¤ºå±æ§Toolçï¼ææ¶åæ们éè¦å¯¹çªå£çå±æ§è¿è¡å¨æ设置ï¼æ¯å¦å¢å ä¸ä¸ªå±æ§æè 移é¤ä¸ä¸ªå±æ§ï¼Qt5.9以åéè¦æ¿å°åæççªä½å±æ§åè¿ç®ï¼åé¢å¯ä»¥ç¨æ°çæ¹æ³ã
//å¢å ä¸ä¸ªæ è¾¹æ¡å±æ§
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
//移é¤æ è¾¹æ¡å±æ§
setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
//ä¸é¢æ¯5.9以åæ°å¢çæ¹æ³
//å¢å ä¸ä¸ªæ è¾¹æ¡å±æ§å°çªä½å±æ§é¾è¡¨
setWindowFlag(Qt::FramelessWindowHint, true);
//ä»çªä½å±æ§é¾è¡¨ä¸ç§»é¤æ è¾¹æ¡å±æ§
setWindowFlag(Qt::FramelessWindowHint, false);
- å¦æ对çªä½è®¾ç½®äºåºå®å°ºå¯¸ï¼çªä½ä¼åå¾å¤§å°ä¸å¯æ伸ï¼å¦æéè¦éæ°è¿åå¯æ伸ï¼å¿ é¡»éæ°è®¾ç½®æå°å°ºå¯¸åæ大尺寸ã
setMinimumSize(0, 0);
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
- Qtå ç½®äºå¾å¤å ¨å±ç对象åæ°å¯ä»¥ç´æ¥è·åï¼è¿æ ·å¨ä½¿ç¨çæ¶åæ¹ä¾¿çä¸è¦ä¸è¦çï¼æ¯å¦å¤æå½åé¼ æ å·¦é®è¿æ¯å³é®å¯ä»¥ç´æ¥ç¨qApp->mouseButtons()ï¼å ¨å±çé¼ æ åæ å¯ä»¥ç¨QCursor::pos()ã
//å¨é¼ æ å³é®çå°æ¹å¼¹åºèåï¼å¦æèåæ¯QMenuèä¸æ¯QActionååªè½éè¿ä¸é¢çæ¹å¼å¼¹åº
if (qApp->mouseButtons() == Qt::RightButton) {
videoMenu->exec(QCursor::pos());
}
//å
¨å±åªåæ¿
qApp->clipboard();
//顶å±æ§ä»¶å¯¹è±¡éå
qApp->topLevelWidgets()
//å½åç¦ç¹æå¨æ§ä»¶
qApp->focusWidget()
//å½åå¹³å°å称
qApp->platformName()
//è°ç¨ç³»ç»è鸣å¨
qApp->beep()
//æå°å½åQtçæ¬ä¿¡æ¯
qApp->aboutQt()
//设置å
¨å±çé¼ æ æ ·å¼
qApp->setOverrideCursor()
//ä¸ä½¿ç¨ç³»ç»çæ åé¢è²åä½ç
QGuiApplication::setDesktopSettingsAware(bool on);
QApplication app(argc, argv);
//æ´å¤çå
¨å±å¯¹è±¡å±æ§çå¯ä»¥æ¥é
qguiapplication.h 头æ件ï¼ä½ ä¼åç°æ°å¤§éã
- Qt对åºåä¸åçç¼è¯å¨ä¹åäºé常ç»è´çå¤çã
#proæ件å¯ä»¥è¿æ ·å¤æ
msvc {
//è¦åçå¤ç
}
mingw {
//è¦åçå¤ç
}
//代ç ä¸å¯ä»¥è¿æ ·å¤æ
#ifdef Q_CC_MINGW
//mingwç¼è¯å¨
#elif Q_CC_MSVC
//msvcç¼è¯å¨
#endif
//å¤æç¼è¯å¨åç¼è¯å¨çæ¬
#if defined Q_CC_MSVC && _MSC_VER < 1300
#if defined(Q_CC_GNU) && (__GNUC__ < 4)
//代ç ä¸å¤æARMå¹³å°
#ifdef QT_ARCH_ARM
//å¤ä¸ªæ¡ä»¶å¤æ
#if defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
- ææ¶åéè¦ææ¶åæ¢æ个æ§ä»¶åå°ä¿¡å·ï¼æ¯å¦ä¸ææ¡comboboxæ·»å æ°æ®çæ¶åä¼è§¦åå½åå ç´ æ¹åä¿¡å·ï¼ï¼æå¤ç§å¤çï¼æ¨èç¨ blockSignals æ¹æ³ã
//æ¹æ³1ï¼å
disconnect æä¿¡å·ï¼å¤ç好以åå connect ä¿¡å·ï¼ç¼ºç¹å¾ææ¾ï¼å¾å»ï¼å¦æä¿¡å·å¾å¤ï¼æ¯ä¸ªåå·é½è¦è¿ä¹æ¥ä¸æ¬¡ã
disconnect(ui->cbox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_cbox_currentIndexChanged(int)));
for (int i = 0; i <= 100; i++) {
ui->cbox->addItem(QString::number(i));
}
connect(ui->cbox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_cbox_currentIndexChanged(int)));
//æ¹æ³2ï¼å
è°ç¨ blockSignals(true) é»å¡ä¿¡å·ï¼å¤çå·ä»¥ååè°ç¨ blockSignals(false) æ¢å¤ææä¿¡å·ã
//å¦æéè¦æå®æ个信å·è¿è¡æå¼é£å°±åªè½ç¨ disconnect æ¥å¤çã
ui->cbox->blockSignals(true);
for (int i = 0; i <= 100; i++) {
ui->cbox->addItem(QString::number(i));
}
ui->cbox->blockSignals(false);
- 项ç®ä»£ç æ件æ°éå¦æå¾å¤çè¯ï¼å ¨é¨å å«å¨pro项ç®æ件ä¸ä¼æ¾å¾é常åä¹±ï¼çè³æ»å¨æ¡é½è¦æå¥½ä¹ ï¼æ两个æ¹æ³å¯ä»¥å¤ççæ´å¥½ï¼æ¨èæ¹æ³2ã
//æ¹æ³1ï¼proæ件ç´æ¥å
¨é¨å¼å
¥ï¼èä¸æ¯æ¯ä¸ªé½æ·»å ä¸æ¬¡ï¼çå¿çåã
HEADERS += *.h
SOURCES += *.cpp
//æ¹æ³2ï¼å模åæ件夹åæ¾ï¼ä¸å模åç¨priå
å«ä»£ç æ件ï¼æ¯å¦çé¢å¯ä»¥æ¾å¨uiæ件夹ï¼ä¸é¢æ个ui.priï¼ç¶åpro项ç®æ件åªéè¦å¼å
¥è¿ä¸ªpriæ件å³å¯ã
include($$PWD/ui/ui.pri)
//è¿å¯ä»¥å ä¸ä¸å¥å
å«è·¯å¾è¿æ ·å¯ä»¥çå»å¨ä½¿ç¨ä»£ç çæ¶åä¸ç¨åæ件夹
INCLUDEPATH += $$PWD/ui
//å ä¸ä¸é¢è¿è¡ï¼å¨ä½¿ç¨å¤´æ件çæ¶åå¯ä»¥ç´æ¥ include "form.h"ï¼æ²¡æå åéè¦ include "ui/form.h"ã
- å¨ç½ç»éä¿¡ä¸ï¼æ 论æ¯tcp客æ·ç«¯è¿æ¯udp客æ·ç«¯ï¼å ¶å®é½æ¯å¯ä»¥ç»å®ç½å¡IPå端å£çï¼å¾å¤äººåªç¥éæå¡ç«¯å¯ä»¥æå®ç½å¡çå¬ç«¯å£ã客æ·ç«¯å¦æ没æç»å®é信端å£åç±å®¢æ·ç«¯æå¨çæä½ç³»ç»éæºéå¢åé çï¼è¿é为å¥è¿ä¹å¼ºè°ï¼å 为æ æ°äººï¼çè³ä¸ä¹ä¸äºå¤å¹´ç»éªçæ°æ¶ä»£åæ°å·¥ï¼ä»¥ä¸ºå®¢æ·ç«¯ç端å£æ¯æå¡ç«¯åé çï¼å 为ä»ä»¬çå°å¨æå¡ç«¯å»ºç«è¿æ¥åå¯ä»¥æå°åºä¸åç端å£å·ãç½ç»éä¿¡çåæ¹èªå·±å³å®èªå·±è¦ç¨ä»ä¹ç«¯å£ï¼æå¡å¨ç«¯åªè½å³å®èªå·±çå¬çæ¯åªä¸ªç«¯å£ï¼ä¸è½å³å®å®¢æ·ç«¯ç端å£ï¼åç客æ·ç«¯ä¹åªè½å³å®èªå·±ç端å£ã端å£éæºåé ä¸è¬æ¯æç §é¡ºåºéå¢çï¼æ¯å¦å æ¯45110端å£ï¼è¿æ¥éæ°å»ºç«å°±ç¨45111端å£ï¼åªè¦ç«¯å£æ²¡è¢«å ç¨å°±è¿æ ·éå¢ä¸å»ï¼æ以å¾å¤äººä¼é®æ¯å¦å¯ä»¥å¤ç¨ä¸äºç«¯å£ï¼ä¸ç¶ç«¯å£ä¸ç´è¿æ ·é¢ç¹çåé ä¸å»ä¸å¦¥ï¼çè³æäºç¹å®çåºæ¯åéæ±ä¹æ¯ä¼è¦æ±å®¢æ·ç«¯ç»å®ç½å¡å端å£æ¥åæå¡å¨éä¿¡çã
//tcp客æ·ç«¯
QTcpSocket *socket = new QTcpSocket(this);
//æå¼ææè¿æ¥åæä½
socket->abort();
//ç»å®ç½å¡å端å£
socket->bind(QHostAddress("192.168.1.2"), 6005);
//è¿æ¥æå¡å¨
socket->connectToHost("192.168.1.3", 6000);
//æå°éä¿¡ç¨çæ¬å°ç»å®å°åå端å£
qDebug() << socket->localAddress() << socket->localPort();
//æå°éä¿¡æå¡å¨å¯¹æ¹çå°åå端å£
qDebug() << socket->peerAddress() << socket->peerPort() << socket->peerName();
//udp客æ·ç«¯
QUdpSocket *socket = new QUdpSocket(this);
//ç»å®ç½å¡å端å£,没æç»å®è¿æéè¦ç»å®
//éç¨ç«¯å£æ¯å¦ä¸æ ·æ¥å¤ææ¯ä¸ºäºæ¹ä¾¿å¯ä»¥ç´æ¥å¨æç»å®åæ¢ç«¯å£
if (socket->localPort() != 6005) {
socket->abort();
socket->bind(QHostAddress("192.168.1.2"), 6005);
}
//æå®å°åå端å£åéæ°æ®
socket->writeDatagram(buffer, QHostAddress("192.168.1.3"), 6000);
//ä¸é¢æ¯Qt5å¯ä»¥ä½¿ç¨bindï¼Qt4ä¸çQTcpSocketç对åºæ¥å£æ¯protectedç没æ³ç´æ¥ä½¿ç¨ï¼éè¦ç»§æ¿ç±»éæ°å®ç°ææ¥å£æ¾åºæ¥ã
//Qt4ä¸çQUdpSocketæbindå½æ°æ¯å¼æ¾çï¼å¥æªäºï¼ä¸ºä½Qt4ä¸ç¬ç¬QTcpSocketä¸å¼æ¾ã
TcpSocket *socket = new TcpSocket(this);
socket->setLocalAddress(QHostAddress("192.168.1.2"));
socket->setLocalPort(6005);
- å ³äºç½ç»éä¿¡ï¼tcpåudpæ¯ä¸¤ç§ä¸åçåºå±çç½ç»éä¿¡åè®®ï¼ä¸¤è çå¬åéä¿¡ç端å£äºä¸ç¸å¹²çï¼ä¸åçåè®®æè ä¸åçç½å¡IPå°åå¯ä»¥ç¨ç¸åç端å£ãä¹åæ个人说ä»ççµèå± ç¶å¯ä»¥çå¬ä¸æ ·ç端å£è¿è¡éä¿¡ï¼é¢ è¦äºä»ä»¥åç认ç¥ï¼ä¹¦ä¸è¯´çæææ¯ä¸å¯ä»¥ç¸å端å£çï¼åé¢è¿ç¨ä¸çåæ¥éæ©çä¸åçç½å¡IPå°åï¼å½ç¶å¯ä»¥çå¯ã
- tcp对ç½å¡1çå¬äºç«¯å£6000ï¼è¿å¯ä»¥å¯¹ç½å¡2çå¬ç«¯å£6000ã
- tcp对ç½å¡1çå¬äºç«¯å£6000ï¼udp对ç½å¡1è¿å¯ä»¥ç»§ç»çå¬ç«¯å£6000ã
- tcp对ç½å¡1çå¬äºç«¯å£6000ï¼å¨ç½å¡1ä¸å ¶ä»tcpåªè½çå¬6000以å¤ç端å£ã
- udpåè®®ä¹æ¯ä¸é¢çé»è¾ã
- å¼æºçå¾è¡¨æ§ä»¶QCustomPlotå¾ç»å ¸ï¼ä½è è³å°æ¯å «ææå£çº§å«ï¼å¨æ²çº¿æ°æ®å±ç¤ºè¿åæ§è½å½ªæï¼æ»ç»äºä¸äºå®¹æ忽ç¥çç»éªè¦ç¹ã
- å¯ä»¥å°XY轴对è°ï¼ç¶åå½¢æ横åçææï¼æ 论æ¯æ²çº¿å¾è¿æ¯æ±ç¶å¾ï¼åç»å¾ãå 积å¾çï¼é½æ¯æè¿ä¸ªç¹æ§ã
- ä¸éè¦çæ示å¾ä¾å¯ä»¥è°ç¨ legend->removeItem è¿è¡ç§»é¤ã
- 两æ¡æ²çº¿å¯ä»¥è°ç¨ setChannelFillGraph 设置å并为ä¸ä¸ªé¢ç§¯åºåã
- å¯ä»¥å ³éæé¯é½¿ setAntialiased å å¿«ç»å¶é度ã
- å¯ä»¥è®¾ç½®ä¸åç线æ¡æ ·å¼ï¼setLineStyleï¼ãæ°æ®æ ·å¼ï¼setScatterStyleï¼ã
- åæ è½´çç®å¤´æ ·å¼å¯æ´æ¢ setUpperEndingã
- å¯ä»¥ç¨ QCPBarsGroup å®ç°æ±ç¶åç»å¾ï¼è¿ä¸ªç±»å¨å®æ¹demoä¸æ²¡æï¼æ以é常容æ忽ç¥ã
- V2.0å¼å§æ¯ææ°æ®æåºè®¾ç½®ï¼é»è®¤æ¯äº¤ç»QCustomPlotæåºï¼ä¹å¯ä»¥è®¾ç½®setData第ä¸ä¸ªåæ°ä¸ºtrue表示已ç»æåºè¿ï¼è¿æ ·å¯ä»¥ç»å¶å¾åèµ°çæ²çº¿ã
- é¢ç¹ç»å¶æ°æ®å¯ä»¥è®¾ç½®æéç»å¶åæ° replot(QCustomPlot::rpQueuedReplot)ï¼å¯ä»¥é¿å éå¤çreplotåæé«æ§è½ãå¦æä¸å¼å¯å¾å¯è½ç»å¶åºéã
- å¯ä»¥å°å¤ä¸ªplotå¾è¡¨å并å°ä¸ä¸ªQCustomPlotæ§ä»¶ä¸ï¼æ大æåç»å¶æçï¼èä¸æ¯å®ä¾åå¤ä¸ªQCustomPlotæ§ä»¶ãå并åä¹æ¯åå¼å¯¹åºä¸åçåæ è½´ä¸åä½ç½®æåæ¾ç¤ºï¼åå¤ä¸ªQCustomPlotæ§ä»¶ææä¸æ ·å¹¶ä¸æ大æåæ§è½ã
//对è°XYè½´ï¼å¨æåé¢è®¾ç½®
QCPAxis *yAxis = customPlot->yAxis;
QCPAxis *xAxis = customPlot->xAxis;
customPlot->xAxis = yAxis;
customPlot->yAxis = xAxis;
//移é¤å¾ä¾
customPlot->legend->removeItem(1);
//å并两个æ²çº¿ç»å¸å½¢æå°éåºå
customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
//å
³éæé¯é½¿ä»¥å设置æå¨çæ¶åä¸å¯ç¨æé¯é½¿
customPlot->setNoAntialiasingOnDrag(true);
customPlot->graph()->setAntialiased(false);
customPlot->graph()->setAntialiasedFill(false);
customPlot->graph()->setAntialiasedScatters(false);
//设置快éç»å¶å¯ä»¥æ大å å¿«ç»ç¬å®½åº¦å¤§äº1ç线æ¡
customPlot->setPlottingHint(QCP::phFastPolylines);
//å¤ç§è®¾ç½®æ°æ®çæ¹æ³
customPlot->graph(0)->setData();
customPlot->graph(0)->data()->set();
//设置ä¸åç线æ¡æ ·å¼ãæ°æ®æ ·å¼
customPlot->graph()->setLineStyle(QCPGraph::lsLine);
customPlot->graph()->setScatterStyle(QCPScatterStyle::ssDot);
customPlot->graph()->setScatterStyle(QCPScatterStyle(shapes.at(i), 10));
//è¿å¯ä»¥è®¾ç½®ä¸ºå¾çæè
èªå®ä¹å½¢ç¶
customPlot->graph()->setScatterStyle(QCPScatterStyle(QPixmap("./sun.png")));
QPainterPath customScatterPath;
for (int i = 0; i < 3; ++i) {
customScatterPath.cubicTo(qCos(2 * M_PI * i / 3.0) * 9, qSin(2 * M_PI * i / 3.0) * 9, qCos(2 * M_PI * (i + 0.9) / 3.0) * 9, qSin(2 * M_PI * (i + 0.9) / 3.0) * 9, 0, 0);
}
customPlot->graph()->setScatterStyle(QCPScatterStyle(customScatterPath, QPen(Qt::black, 0), QColor(40, 70, 255, 50), 10));
//æ´æ¢åæ è½´çç®å¤´æ ·å¼
customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
//设置èæ¯å¾ç
customPlot->axisRect()->setBackground(QPixmap("./solarpanels.jpg"));
//ç»å¸ä¹å¯ä»¥è®¾ç½®èæ¯å¾ç
customPlot->graph(0)->setBrush(QBrush(QPixmap("./balboa.jpg")));
//æ´ä½å¯ä»¥è®¾ç½®å¡«å
é¢è²æè
å¾ç
customPlot->setBackground(QBrush(gradient));
//设置é¶ç¹çº¿æ¡é¢è²
customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
//æ§å¶æ¯å¦é¼ æ æ»è½®ç¼©æ¾æå¨ç交äºå½¢å¼
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
//æ±ç¶åç»å¾
QCPBarsGroup *group = new QCPBarsGroup(customPlot);
QList<QCPBars*> bars;
bars << fossil << nuclear << regen;
foreach (QCPBars *bar, bars) {
//设置æ±ç¶å¾ç宽度大å°
bar->setWidth(bar->width() / bars.size());
group->append(bar);
}
//设置åç»ä¹é´çé´é
group->setSpacing(2);
//ç»å¶å¾åèµ°çæ²çº¿
QVector<double> keys, values;
keys << 0 << 1 << 2 << 3 << 4 << 5 << 4 << 3;
values << 5 << 4 << 6 << 7 << 7 << 6 << 5 << 4;
customPlot->graph(0)->setData(keys, values, true);
//é¢ç¹ç»å¶æ°æ®å¼å¯æéç»å¶å¯ä»¥æé«æ§è½
customPlot->replot(QCustomPlot::rpQueuedReplot);
QCPAxis *axis = customPlot->xAxis;
double lower = axis->range().lower;
double upper = axis->range().upper;
double origin = (upper - lower) / 2;
//设置å»åº¦çº¿æç
§è®¾ç½®ä¼å
èä¸æ¯å¯è¯»æ§ä¼å
axis->ticker()->setTickStepStrategy(QCPAxisTicker::tssMeetTickCount);
//设置åç¹å¼ä¸ºèå´å¼çä¸å¿ç¹
axis->ticker()->setTickOrigin(origin);
//ä¸é¢æ¼ç¤ºå¦ä½å¨ä¸ä¸ªæ§ä»¶ä¸å¤ä¸ªä¸åçæ²çº¿å¯¹åºä¸ååæ è½´
//æ¿å°å¾è¡¨å¸å±å¯¹è±¡
QCPLayoutGrid *layout = customPlot->plotLayout();
//å®ä¾ååæ è½´åºå
QCPAxisRect *axisRect = new QCPAxisRect(customPlot);
//æ¿å°XYåæ 轴对象
QCPAxis *xAxis = axisRect->axis(QCPAxis::atBottom);
QCPAxis *yAxis = axisRect->axis(QCPAxis::atLeft);
//å°åæ è½´æå®è¡åä½ç½®æ·»å å°å¸å±ä¸
layout->addElement(i, 0, axisRect);
//æ·»å 对åºçç»å¸å°æå®åæ è½´
QCPGraph *graph = customPlot->addGraph(xAxis, yAxis);
18ï¼171-180
- å¨Qtç¼ç¨ä¸ç»å¸¸ä¼éå°ç¼ç çé®é¢ï¼ç±äºè·¨å¹³å°çèèå ¼å®¹åç§ç³»ç»ï¼èwindowsç³»ç»é»è®¤æ¯gbkæè gb2312ç¼ç ï¼å½ç¶åæå¯è½msvcç¼è¯å¨é½æ¯æutf8ç¼ç ï¼æ以å¨é¨åç¨åºä¸ä¼ å ¥ä¸æç®å½æ件å称çæ¶åä¼åç°å¤±è´¥ï¼å 为å¯è½å¯¹åºçæ¥å£ç¨äºæ©æçfopenå½æ°èä¸æ¯fopen_så½æ°ï¼æ¯å¦fmodä¸ä¹æ¯è¿ä¸ªæ åµãè¿ä¸ªæ¶åå°±éè¦è½¬ç å¤çã
QString fileName = "c:/æµè¯ç®å½/1.txt";
//å¦æåºç¨ç¨åºmainå½æ°ä¸æ²¡æ设置ç¼ç åé»è®¤éç¨ç³»ç»çç¼ç ï¼å¯ä»¥ç´æ¥éè¿toLocal8Bit转ææ£ç¡®çæ°æ®
const char *name = fileName.toLocal8Bit().constData();
//å¦æ设置è¿äºä¸é¢ä¸¤å¥åéè¦ä¸»å¨è½¬ç
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec *code = QTextCodec::codecForName("gbk");
const char *name = code->fromUnicode(fileName).constData();
//æ¨èæ¹å¼2以é²ä¸ä¸ä¿è¯ç»å¯¹çæ£ç¡®ï¼åªææ¯è®¾ç½®è¿ä¸»ç¨åºçç¼ç
//åè®°ä¸æ¦è®¾ç½®è¿QTextCodec::setCodecForLocaleä¼å½±åtoLocal8Bit
//ææ¶åå¯è½è¿æä¸é¢è¿ç§æ
åµ
#ifdef Q_OS_WIN
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
QTextCodec *code = QTextCodec::codecForName("utf-8");
#else
QTextCodec *code = QTextCodec::codecForName("gbk");
#endif
const char *name = code->fromUnicode(fileName).constData();
#else
const char *name = fileName.toUtf8().constData();
#endif
- å¨æ¥é åå¦ä¹ Qtæºç çè¿ç¨ä¸ï¼åç°äºä¸äºè¶å¿åæ¹åã
- æ°æ®ç±»åè¿åå°½éç¨Qtå é¨çæ°æ®ç±»åï¼åªææ¯éå®ä¹è¿çæ¯å¦quint8å ¶å®unsigned charï¼qrealå°±æ¯doubleï¼ä»¥åç¿»çæºç çæ¶åå¯è½è¿æäºæ¯doubleï¼ç°å¨æ ¢æ ¢æ¹æäºqrealã
- 循ç¯ç»æç¨ for(;;) æ¿ä»£ while(1)ï¼å 为转ææ±ç¼æ令å for(;;) åªæä¸æ¡æ令è while(1) ç¡®æ4æ¡ï¼æ令å°ä¸å ç¨å¯åå¨èä¸ä¸ç¨è·³è½¬ï¼ç论ä¸é度è¦æ´å¿«ã
- å ¶å®Qtä¸å°±éå®ä¹äº forever å ³é®å表示 for(;;) ï¼æçä¹ä¹ï¼æ³ççå¨å°ã
- èªå¨c++11以ååç»çæ åé½æ¯æautoä¸è½æ°æ®ç±»åï¼åç°Qtçæºç ä¸ä¹æ ¢æ ¢çæ¹æäºautoï¼è¿æ ·å å¿«äºç¼å代ç çæçï¼ä¸ç¨èªå·±å»æå®æ°æ®ç±»åèæ¯è®©ç¼è¯å¨èªå·±æ¨å¯¼æ°æ®ç±»åãèä¸å ¶å®ä¹ä¸å½±åç¼è¯å¨ç¼è¯çé度ï¼å 为æ 论æå®å没ææå®æ°æ®ç±»åï¼ç¼è¯å¨é½è¦æ¨å¯¼å³ä¾§çæ°æ®ç±»åè¿è¡å¤æãä¸è¿æ个缺ç¹å°±æ¯å½±åäºé 读代ç çææ¬ï¼å¾å¤æ¶åéè¦èªå·±å»ç解æ¨å¯¼ã
- Qtä¸è®¾ç½®æè æå¼å è½½æ¬å°æ件éè¦ç¨å°QUrlç±»ï¼æ¬å°æ件建议å ä¸ file:/// åç¼ã
QString url = "file:///c:/1.html";
//æµè§å¨æ§ä»¶æå¼æ¬å°ç½é¡µæ件
webView->setUrl(QUrl(url));
//æå¼æ¬å°ç½é¡µæ件ï¼ä¸é¢ä¸¤ç§æ¹æ³é½å¯ä»¥
QDesktopServices::openUrl(QUrl::fromLocalFile(url));
QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
- å¨ç½ç»è¯·æ±ä¸ç»å¸¸æ¶åå°è¶ æ¶æ¶é´çé®é¢ï¼å 为é»è®¤æ¯30ç§éï¼ä¸æ¦éå°ç½ç»æ éçæ¶åè¦çå¥½ä¹ æè½ååºè¿æ¥ï¼æ以éè¦ä¸»å¨è®¾ç½®ä¸è¶ æ¶æ¶é´ï¼è¶ è¿äºå°±ç´æ¥ä¸æç»æ请æ±ãä»Qt5.15å¼å§å ç½®äºsetTransferTimeoutæ¥è®¾ç½®è¶ æ¶æ¶é´ï¼é常好ç¨ã
//å±é¨çäºä»¶å¾ªç¯,ä¸å¡ä¸»çé¢
QEventLoop eventLoop;
//设置è¶
æ¶ 5.15å¼å§èªå¸¦äºè¶
æ¶æ¶é´å½æ° é»è®¤30ç§
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
manager->setTransferTimeout(timeout);
#else
QTimer timer;
connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(timeout);
#endif
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec();
if (reply->bytesAvailable() > 0 && reply->error() == QNetworkReply::NoError) {
//读åæææ°æ®ä¿åææ件
QByteArray data = reply->readAll();
QFile file(dirName + fileName);
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
file.write(data);
file.close();
}
}
- Qtä¸åºæ¬ä¸æä¸å¤§ç±»åç项ç®ï¼æ§å¶å°é¡¹ç®å¯¹åºQCoreApplicationãä¼ ç»QWidgetçé¢ç¨åºå¯¹åºQApplicationãquick/qml项ç®ç¨åºå¯¹åºQGuiApplicationãæå¾å¤å±æ§çå¼å¯éè¦å¨mainå½æ°çæåé¢æ§è¡ææææï¼æ¯å¦å¼å¯é«åå±æ¯æã设置opengl模å¼çãä¸åç±»åç项ç®éè¦å¯¹åºçQApplicationã
//å¦ææ¯æ§å¶å°ç¨åºåä¸é¢çQApplicationæ¢æQCoreApplication
//å¦ææ¯quick/qmlç¨åºåä¸é¢çQApplicationæ¢æQGuiApplication
int main(int argc, char *argv[])
{
//å¯ä»¥ç¨ä¸é¢è¿è¡æµè¯Qtèªå¸¦çè¾å
¥æ³ qtvirtualkeyboard
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
//设置ä¸åºç¨æä½ç³»ç»è®¾ç½®æ¯å¦åä½
QApplication::setDesktopSettingsAware(false);
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
//设置é«åå±ç¼©æ¾èå
¥çç¥
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
#if (QT_VERSION > QT_VERSION_CHECK(5,6,0))
//设置å¯ç¨é«åå±ç¼©æ¾æ¯æ
//è¦æ³¨æå¼å¯å计ç®å°çæ§ä»¶æçé¢å®½åº¦é«åº¦å¯è½é½ä¸å¯¹,å
¨é¨éè¦ç¨ç¼©æ¾æ¯ä¾è¿ç®ä¸
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//设置å¯ç¨é«åå±å¾çæ¯æ
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
#if (QT_VERSION > QT_VERSION_CHECK(5,4,0))
//设置openglæ¨¡å¼ AA_UseDesktopOpenGL(é»è®¤) AA_UseOpenGLES AA_UseSoftwareOpenGL
//å¨ä¸äºå¾æ§ç设å¤ä¸æè
对openglæ¯æå¾ä½ç设å¤ä¸éè¦ä½¿ç¨AA_UseOpenGLES表示ç¦ç¨ç¡¬ä»¶å é
//å¦æå¼å¯çæ¯AA_UseOpenGLESåæ æ³ä½¿ç¨ç¡¬ä»¶å éæ¯å¦ffmpegçdxva2
//QApplication::setAttribute(Qt::AA_UseOpenGLES);
//设置openglå
±äº«ä¸ä¸æ
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif
QApplication a(argc, argv);
QWidget w;
w.show();
return a.exec();
}
- QCameraä¸è·å设å¤çé ç½®åæ°æ¯å¦æ¯æçå辨çéåçï¼éè¦å è°ç¨loadåæè½æ£ç¡®è·åï¼æè å ³èstateChangedä¿¡å·ä¸å¤æç¶ææ¯å¦æ¯ActiveStateï¼ç¶åå读åã
//æ¹æ³1ï¼è°ç¨loadåè·å
camera = new QCamera(this);
//å
éè¦è½½å
¥æè½è·åå°å¯¹åºåæ°
camera->load();
//è¾åºå½å设å¤æ¯æçå辨ç
QList<QSize> sizes = camera->supportedViewfinderResolutions();
emit resolutions(sizes);
//éæ°è®¾ç½®å辨ç
QCameraViewfinderSettings set;
set.setResolution(cameraWidth, cameraHeight);
camera->setViewfinderSettings(set);
//è·åå®æåå¸è½½
camera->unload();
//æ¹æ³2ï¼éè¿äºä»¶ä¿¡å·è·å
camera = new QCamera(this);
connect(camera, SIGNAL(stateChanged(QCamera::State)), this, SLOT(stateChanged(QCamera::State)));
void CameraThread::stateChanged(QCamera::State state)
{
if (state == QCamera::ActiveState) {
//è¾åºå½å设å¤æ¯æçå辨ç
QList<QSize> sizes = camera->supportedViewfinderResolutions();
emit resolutions(sizes);
//éæ°è®¾ç½®å辨ç
QCameraViewfinderSettings set;
set.setResolution(cameraWidth, cameraHeight);
camera->setViewfinderSettings(set);
}
}
//QCamera没ææå®è®¾å¤å称çæ¶ååéç¨é»è®¤çæåæº
camera = new QCamera(this);
//cameraName = @device:pnp:\\\\?\\usb#vid_046d&pid_0825&mi_00#6&212eebd3&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global
//å¯ä»¥éè¿è®¾å¤æ述符æ¥æ¥æ¾è®¾å¤å称(å¯ä¸æ è¯)
camera = new QCamera(cameraName.toUtf8(), this);
- å¾å¤æ¶åéè¦å¨çªä½é¦æ¬¡æ¾ç¤ºçæ¶åå è½½ä¸äºä¸è¥¿ï¼èä¸åªå è½½ä¸æ¬¡ï¼å½çªä½å次æ¾ç¤ºçæ¶åä¸å è½½ã为ä»ä¹ä¸æ¯å¨æé å½æ°å¢ï¼å 为å¾å¤ç©æé½æ¯è¦å¨æ¾ç¤ºåæè½ç¡®å®ï¼æ¯å¦æ§ä»¶ç尺寸ï¼é¨åæ ·å¼è¡¨çåºç¨ã
void Widget::showEvent(QShowEvent *)
{
//è¿é为äºæ¼ç¤ºä»£ç æ¹ä¾¿ç´æ¥åçstaticï¼å¦ænewå¤ä¸ªçªä½åéè¦å®ä¹å¨å¤´æ件ä¸ã
static bool isLoad = false;
if (!isLoad) {
isLoad = true;
//æ§è¡å¯¹åºçå¤ç
}
}
- Qtè·åå½åæç¨çQtçæ¬ãç¼è¯å¨ãä½æ°çä¿¡æ¯ã
//详ç»çQtçæ¬+ç¼è¯å¨+ä½æ°
QString compilerString = "<unknown>";
{
#if defined(Q_CC_CLANG)
QString isAppleString;
#if defined(__apple_build_version__)
isAppleString = QLatin1String(" (Apple)");
#endif
compilerString = QLatin1String("Clang ") + QString::number(__clang_major__) + QLatin1Char('.') + QString::number(__clang_minor__) + isAppleString;
#elif defined(Q_CC_GNU)
compilerString = QLatin1String("GCC ") + QLatin1String(__VERSION__);
#elif defined(Q_CC_MSVC)
if (_MSC_VER > 1999) {
compilerString = QLatin1String("MSVC <unknown>");
} else if (_MSC_VER >= 1930) {
compilerString = QLatin1String("MSVC 2022");
} else if (_MSC_VER >= 1920) {
compilerString = QLatin1String("MSVC 2019");
} else if (_MSC_VER >= 1910) {
compilerString = QLatin1String("MSVC 2017");
} else if (_MSC_VER >= 1900) {
compilerString = QLatin1String("MSVC 2015");
} else if (_MSC_VER >= 1800) {
compilerString = QLatin1String("MSVC 2013");
} else if (_MSC_VER >= 1700) {
compilerString = QLatin1String("MSVC 2012");
} else if (_MSC_VER >= 1600) {
compilerString = QLatin1String("MSVC 2010");
} else {
compilerString = QLatin1String("MSVC <old>");
}
#endif
}
//æå±ç¥è¯ æ¥ç QSysInfo ç±»ä¸é¢æå¾å¤å¥½ä¸è¥¿
// qVersion() = QT_VERSION_STR
QString version = QString("%1 %2 %3").arg(qVersion()).arg(compilerString).arg(QString::number(QSysInfo::WordSize));
- QDateTimeå¯ä»¥ç´æ¥æ ¼å¼åè¾åºææå å¨å ï¼Qt6é»è®¤æç §è±æè¾åºæ¯å¦ ddd = å¨äº Tue dddd = ææäº Tuesday ï¼æ¤æ¶å¦æåªæ³æ°¸è¿æ¯ä¸æå°±éè¦ç¨å°QLocaleè¿è¡è½¬æ¢ã
//æ ¼å¼åè¾åºåå°æ¬å°æä½ç³»ç»è¯è¨çå½±å
//è±ææä½ç³»ç»
//è¿æ ·è·åå°çæ¯Monå°Sunï¼è±æææç3个åæ¯ç缩åã
QDateTime::currentDateTime().toString("ddd");
//è¿æ ·è·åå°çæ¯Mondayå°Sundayï¼è±æææå®æ´åè¯ã
QDateTime::currentDateTime().toString("dddd");
//ä¸ææä½ç³»ç»
//è¿æ ·è·åå°çæ¯å¨ä¸å°å¨æ¥ã
QDateTime::currentDateTime().toString("ddd");
//è¿æ ·è·åå°çæ¯ææä¸å°æææ¥ã
QDateTime::currentDateTime().toString("dddd");
//主å¨æå®è¯è¨è½¬æ¢
//å¦æ没ææå®æ¬å°è¯è¨åé»è®¤éç¨ç³»ç»çè¯è¨ç¯å¢ã
QLocale locale;
//QLocale locale = QLocale::Chinese;
//QLocale locale = QLocale::English;
//QLocale locale = QLocale::Japanese;
//ä¸é¢æ°¸è¿è¾åºä¸æçå¨ä¸å°å¨æ¥
locale.toString(QDateTime::currentDateTime(), "ddd");
//ä¸é¢æ°¸è¿è¾åºä¸æçææä¸å°æææ¥
locale.toString(QDateTime::currentDateTime(), "dddd");
- QSqlTableModelæ大ç®åäºå¯¹æ°æ®åºè¡¨çæ¾ç¤ºãæ·»å ãå é¤ãä¿®æ¹çï¼å¯ç¬å¯¹æ°æ®åºå页æä½æç¹ç»å¼¯ã
//å®ä¾åæ°æ®åºè¡¨æ¨¡å
QSqlTableModel *model = new QSqlTableModel(this);
//æå®è¡¨å
model->setTable("table");
//设置åæåº
model->setSort(0, Qt::AscendingOrder);
//设置æ交模å¼
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
//ç«å³æ¥è¯¢ä¸æ¬¡
model->select();
//å°æ°æ®åºè¡¨æ¨¡å设置å°è¡¨æ ¼ä¸
ui->tableView->setModel(model);
//æµè¯åç°è¿æ»¤æ¡ä»¶ä¸é¤äºå¯ä»¥å¸¦whereè¯å¥è¿å¯ä»¥å¸¦æåºålimitç
model->setFilter("1=1 order by id desc limit 100");
//å¦æå¨è¿æ»¤æ¡ä»¶ä¸è®¾ç½®äºæåºè¯å¥åä¸å¯ä»¥å使ç¨setSortæ¹æ³
//ä¸é¢ç代ç ç»ææ¯æ§è¡åºéï¼å¯è½å 为setSortåéæ°å¢å äºorder byè¯å¥å¯¼è´å¤ä¸ªorder byè¯å¥å²çªäºã
model->setSort(0, Qt::AscendingOrder);
model->setFilter("1=1 order by id desc limit 100");
//éè¿setFilter设置å纯çwhereè¯å¥å¯ä»¥ä¸ç¨å 1=1
model->setFilter("name='å¼ ä¸'");
//å¦æè¿æå
¶ä»è¯å¥æ¯å¦æåºæè
limitçåéè¦æåé¢å ä¸1=1
//ä¸é¢è¡¨ç¤ºæç
§idååºæåºï¼æ¥è¯¢ç»ææ¾ç¤ºç¬¬5-15æ¡è®°å½ã
model->setFilter("1=1 order by id asc limit 5,10");
//å¤ä¸ªæ¡ä»¶ç¨andè¿æ¥
//建议任ä½æ¶åç¨äºsetFilteråæåé¢å1=1ææ«å°¾å ä¸ ; é²æ¢æäºå°æ¹æ æ³æ£ç¡®æ§è¡ã
model->setFilter("1=1 and name='å¼ ä¸' and result>=70;");
//ä¸é¢è¡¨ç¤ºæ¥è¯¢å§åæ¯å¼ ä¸çè®°å½ï¼æç
§idå段éåºæåºï¼ç»æä»ç¬¬10æ¡å¼å§100æ¡ï¼ç¸å½äºä»ç¬¬10æ¡å°110æ¡è®°å½ã
model->setFilter("1=1 and name='å¼ ä¸' order by id desc limit 10,100;");
//å¨ç¬¬3è¡å¼å§æ·»å ä¸æ¡è®°å½
model->insertRow(2);
//ç«å³å¡«å
ååæ°å¢å çè¡ï¼é»è®¤ä¸ºç©ºéè¦ç¨æ·æå¨å¨è¡¨æ ¼ä¸è¾å
¥ã
model->setData(model->index(2, 0), 100);
model->setData(model->index(2, 1), "å¼ ä¸");
//æ交æ´æ°
model->submitAll();
//å é¤ç¬¬4è¡
model->removeRow(3);
model->submitAll();
//æ»ä¹æå¢å æ¹æä½åé½éè¦è°ç¨model->submitAll();æ¥çæ£æ§è¡ï¼å¦åä»
ä»
æ¯æ°æ®æ¨¡åæ´æ°äºæ°æ®ï¼å¹¶ä¸ä¼æ´æ°å°æ°æ®åºä¸ã
//æ¤éæ´æ¹
model->revertAll();
19ï¼181-190
- Qt天çå°±æ¯linuxçï¼ä»linuxå¼å§åå±èµ·æ¥çï¼æ以ä¸å°Qtç¨åºåç»å¸¸çå¼åç¯å¢æ¯linuxï¼æ¯å¦å¸¸ç¨çubuntuçç³»ç»ï¼æ´çäºä¸ç¹å¸¸ç¨çlinuxå½ä»¤ã
å½ä»¤ | åè½ |
---|---|
sudo -s | åæ¢å°ç®¡çåï¼å¦ææ¯ sudo -i åæ¢åä¼æ¹åå½åç®å½ã |
apt install g++ | å®è£ 软件å ï¼è¦ç®¡çåæéï¼ï¼å¦ä¸ä¸ªæ´¾ç³»çæ¯ yum installã |
cd /home | è¿å ¥homeç®å½ã |
ls | ç½åå½åæå¨ç®å½ææç®å½åæ件ã |
ifconfig | æ¥çç½å¡ä¿¡æ¯å æ¬IPå°åï¼windowsä¸æ¯ ipconfigã |
tar -zxvf bin.tar.gz | 解åæ件å°å½åç®å½ã |
tar -jxvf bin.tar.xz | 解åæ件å°å½åç®å½ã |
tar -zxvf bin.tar.gz -C /home | 解åæ件å°/homeç®å½ï¼è®°ä½æ¯å¤§åçCã |
tar -zcvf bin.tar.gz bin | å°binç®å½å缩ætar.gzæ ¼å¼æ件ï¼å缩æ¯ä¸è¬ï¼ã |
tar -jcvf bin.tar.xz bin | å°binç®å½å缩ætar.xzæ ¼å¼æ件ï¼å缩æ¯é«ï¼æ¨èï¼ã |
tar -... | j z 表示ä¸åçå缩æ¹æ³ï¼x表示解åï¼c表示å缩ã |
gedit 1.txt | ç¨è®°äºæ¬æå¼ææ¬æ件ã |
vim 1.txt | ç¨vimæå¼æ件ï¼å¾å¤æ¶åå¯ä»¥ç¼©åç¨viã |
./configure make -j4 make install | éç¨ç¼è¯æºç å½ä»¤ï¼ç¬¬ä¸æ¥./configureæ§è¡é ç½®èæ¬ï¼ç¬¬äºæ¥make -j4å¯ç¨å¤çº¿ç¨ç¼è¯ï¼ç¬¬ä¸æ¥make installå®è£ ç¼è¯å¥½çæ件ã |
./configure -prefix /home/liu/Qt-5.9.3-static -static -sql-sqlite -qt-zlib -qt-xcb -qt-libpng -qt-libjpeg -fontconfig -system-freetype -iconv -nomake tests -nomake examples -skip qt3d -skip qtdoc | Qtéç¨ç¼è¯å½ä»¤ã |
./configure -static -release -fontconfig -system-freetype -qt-xcb -qt-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -nomake tests -nomake examples -prefix /home/liu/qt/Qt5.6.3 | Qtéæ带ä¸æã |
./configure -prefix /home/liu/Qt-5.9.3-static -static -release -nomake examples -nomake tests -skip qt3d | ç²¾ç®ç¼è¯å½ä»¤ã |
./configure --prefix=host --enable-static --disable-shared --disable-doc | ffmpegç¼è¯å½ä»¤ã |
- Qtèªå¸¦çæ¥å¿éå®åæºå¶é常ç®å好ç¨ï¼èªä»ç¨äºä»¥ååä¹ä¸ç¨ä»ä¹æç¹è°è¯å¥çäºï¼å¨éè¦çå°æ¹æ¯æqdebugè¾åºå¯¹åºçä¿¡æ¯ï¼èä¸åå¸ç¨åºä»¥åä¹å¯ä»¥å¼å¯è°è¯æ¥å¿å°å ¶è¾åºæ¥ççã
//Qt5å¼å§æä¾äºæ¥å¿ä¸ä¸æä¿¡æ¯è¾åºï¼æ¯å¦è¾åºå½åæå°æ¶æ¯æå¨ç代ç æ件ãè¡å·ãå½æ°åçã
//å¦ææ¯releaseè¿éè¦å¨proä¸å ä¸ DEFINES += QT_MESSAGELOGCONTEXT æè½è¾åºä¸ä¸æï¼é»è®¤releaseå
³éçã
//åè®°ä¸è¦å¨æ¥å¿é©åå½æ°ä¸ååqdebugä¹ç±»çï¼é£æ ·å°±æ»å¾ªç¯äºã
//æ¥å¿éå®åä¸è¬å°±ä¸ç§å¤ç
//1: è¾åºå°æ¥å¿æ件æ¯å¦txtææ¬æ件ã
//2: åå¨å°æ°æ®åºï¼å¯ä»¥åç±»åå¨ï¼ä»¥ä¾¿ç¸å
³äººåæ¥è¯¢åæã
//3: éå®åå°ç½ç»ï¼å¯¹æ¹ç¨å°å·¥å
·è¿æ¥ç¨åºåï¼æææå°ä¿¡æ¯éè¿tcpåè¿å»ã
//æ¥å¿éå®å
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
void Log(QtMsgType type, const QMessageLogContext &context, const QString &msg)
#else
void Log(QtMsgType type, const char *msg)
#endif
{
//å é,é²æ¢å¤çº¿ç¨ä¸qdebug太é¢ç¹å¯¼è´å´©æº
static QMutex mutex;
QMutexLocker locker(&mutex);
QString content;
//è¿éå¯ä»¥æ ¹æ®ä¸åçç±»åå ä¸ä¸åç头é¨ç¨äºåºå
switch (type) {
case QtDebugMsg:
content = QString("%1").arg(msg);
break;
case QtWarningMsg:
content = QString("%1").arg(msg);
break;
case QtCriticalMsg:
content = QString("%1").arg(msg);
break;
case QtFatalMsg:
content = QString("%1").arg(msg);
break;
}
//å ä¸æå°ä»£ç æå¨ä»£ç æ件ãè¡å·ãå½æ°å
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
if (SaveLog::Instance()->getUseContext()) {
int line = context.line;
QString file = context.file;
QString function = context.function;
if (line > 0) {
content = QString("è¡å·: %1 æ件: %2 å½æ°: %3\n%4").arg(line).arg(file).arg(function).arg(content);
}
}
#endif
//å°å
å®¹ä¼ ç»å½æ°è¿è¡å¤ç
SaveLog::Instance()->save(content);
}
//å®è£
æ¥å¿é©å,è¾åºè°è¯ä¿¡æ¯å°æ件,便äºè°è¯
void SaveLog::start()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qInstallMessageHandler(Log);
#else
qInstallMsgHandler(Log);
#endif
}
//å¸è½½æ¥å¿é©å
void SaveLog::stop()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
qInstallMessageHandler(0);
#else
qInstallMsgHandler(0);
#endif
}
- èªä»c++11æ å以åï¼åç§è¯æ³ç³å±åºä¸ç©·ï¼å ¶ä¸lambda表达å¼ç¨çæ广ï¼åºæ¬ä¸ä»Qt5以åå°±æ¯ælambda表达å¼ã对äºä¹ æ¯äºc99çèä¸è¾çç¨åºåæ¥è¯´ï¼è¿ç©ææ¯ä¸ªæ°é²äºç©ï¼è¿éç¹æå个å°ç解ç¬è®°ã
- 代ç æ ¼å¼ï¼capture mutable ->return-type {statement}
- [capture]ï¼ææå表ï¼ææå表æ»æ¯åºç°å¨Lambdaå½æ°çå¼å§å¤ï¼å®é ä¸ï¼[]æ¯Lambdaå¼åºç¬¦ï¼ç¼è¯å¨æ ¹æ®è¯¥å¼åºç¬¦å¤ææ¥ä¸æ¥ç代ç æ¯å¦æ¯Lambdaå½æ°ï¼ææå表è½å¤ææä¸ä¸æä¸çåé以ä¾Lambdaå½æ°ä½¿ç¨ã
- (parameters)ï¼åæ°å表ï¼ä¸æ®éå½æ°çåæ°å表ä¸è´ï¼å¦æä¸éè¦åæ°ä¼ éï¼åå¯ä»¥è¿åæ¬å· () ä¸èµ·çç¥ã
- mutableï¼mutable修饰符ï¼é»è®¤æ åµä¸ï¼Lambdaå½æ°æ»æ¯ä¸ä¸ªconstå½æ°ï¼mutableå¯ä»¥åæ¶å ¶å¸¸éæ§ãå¨ä½¿ç¨è¯¥ä¿®é¥°ç¬¦æ¶ï¼åæ°å表ä¸å¯çç¥ï¼å³ä½¿åæ°ä¸ºç©ºï¼ã
- ->return-typeï¼è¿åç±»åï¼ç¨è¿½è¸ªè¿åç±»åå½¢å¼å£°æå½æ°çè¿åç±»åï¼æ们å¯ä»¥å¨ä¸éè¦è¿åå¼çæ¶åä¹å¯ä»¥è¿åç¬¦å· -> ä¸èµ·çç¥ãæ¤å¤ï¼å¨è¿åç±»åæç¡®çæ åµä¸ï¼ä¹å¯ä»¥çç¥è¯¥é¨åï¼è®©ç¼è¯å¨å¯¹è¿åç±»åè¿è¡æ¨å¯¼ã
- {statement}ï¼å½æ°ä½ï¼å 容ä¸æ®éå½æ°ä¸æ ·ï¼ä¸è¿é¤äºå¯ä»¥ä½¿ç¨åæ°ä¹å¤ï¼è¿å¯ä»¥ä½¿ç¨æææè·çåéã
ææå表æ以ä¸å ç§å½¢å¼ï¼
- [var]表示å¼ä¼ éæ¹å¼ææåévarã
- [=]表示å¼ä¼ éæ¹å¼ææææç¶ä½ç¨åçåéï¼å æ¬thisï¼ã
- [&var]表示å¼ç¨ä¼ éææåévarã
- [&]表示å¼ç¨ä¼ éæ¹å¼ææææç¶ä½ç¨åçåéï¼å æ¬thisï¼ã
- [this]表示å¼ä¼ éæ¹å¼ææå½åçthisæéã
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//æé®åå»ä¸å¸¦åæ°
connect(ui->pushButton, &QPushButton::clicked, [] {
qDebug() << "hello lambda";
});
//æé®åå»å¸¦åæ°
connect(ui->pushButton, &QPushButton::clicked, [] (bool isCheck) {
qDebug() << "hello lambda" << isCheck;
});
//èªå®ä¹ä¿¡å·å¸¦åæ°
connect(this, &MainWindow::sig_test, [] (int i, int j) {
qDebug() << "hello lambda" << i << j;
});
emit sig_test(5, 8);
}
- ç±äºQtçæ¬ä¼å¤ï¼ææ¶å为äºå ¼å®¹å¤ä¸ªçæ¬çè³è·¨åº¦Qt4/Qt5/Qt6çå ¼å®¹ï¼æäºå¤´æ件æè ç±»åçåäºæè æ°å¢äºï¼éè¦ç¨å°Qtçæ¬çå¤æãéè¦æ³¨æçæ¯å¦æå¨å¤´æ件ä¸ä½¿ç¨ QT_VERSION_CHECK éè¦å å¼å ¥#include "qglobal.h"ä¸ç¶ç¼è¯å¤±è´¥ï¼å 为 QT_VERSION_CHECK è¿ä¸ªå½æ°å¨ qglobal.h 头æ件ä¸ã
//è³å°è¦å
å« qglobal.hï¼ç论ä¸Qtææçç±»é½å
å«äºè¿ä¸ªå¤´æ件ï¼æä»¥ä½ å¼å
¥Qtçå
¶ä»å¤´æ件ä¹è¡æ¯å¦ qobject.h
#include "qglobal.h"
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include "qscreen.h"
#else
#include "qdesktopwidget.h"
#endif
- å¨ä½¿ç¨QString转æ¢å°char *æè const char *çæ¶åï¼å¡å¿ è®°å¾å两æ¥æ¥å®æï¼è¡çæè®ï¼å¨ä¸ä¸ªåºæ¯ä¸ï¼å°±å 为没æå两æ¥èµ°ï¼ç°è±¡æ¯msvcçdebugå¼å¸¸releaseæ£å¸¸ï¼mingwågccçdebugåreleaseé½æ£å¸¸ï¼è¿å°±å¾æ è¯äºï¼æ¾é®é¢æ¾å天ï¼å¯¹æ¯æ³æé¤æ³æéçè¦ä¹é½æé®é¢æ对ã
- 转æ¢åQStringçå 容æ å ³ä¸æè¿æ¯è±æï¼è¦åºé®é¢é½ä¸æ ·ã
- 转æ¢ä¸QByteArrayæ å ³å ·ä½ç±»åï¼toUtf8ãtoLatin1ãtoLocal8BitãtoStdStringçæ¹æ³ï¼è¦åºé®é¢é½ä¸æ ·ã
- 转æ¢åæ å ³char *è¿æ¯const char *ï¼è¦åºé®é¢é½ä¸æ ·ã
- åºé®é¢çéæºæ§çï¼æ¦çåºç°ï¼ç论ä¸debugçæ¦çæ´å¤§ã
- æ ¹æ®é ·ç 大佬åæå¯è½çåå (ä¸ç¡®å®)æ¯msvc为äºæ¹ä¾¿è°è¯ï¼debugä¼å¨å åéæ¾ååå¡«å ï¼releaseåä¸ä¼ã
- æ»ä¹å»ºè®®å两æ¥ï¼å¦ææ¯ä¼ åæ°åå¯ä»¥ç´æ¥æ¾å¨åæ°ä¸ä¼ å ¥ä¹è¡ã
QString text = "xxxxx";
//ä¸é¢è¿æ ·è½¬æ¢å¾å¯è½ä¼æé®é¢
char *data = text.toUtf8().data();
//å两æ¥è½¬æ¢è¯å®ä¸ä¼æé®é¢
QByteArray buffer = text.toUtf8();
char *data = buffer.data();
const char *data = buffer.constData();
void test(const char *text) {}
//å两æ¥èµ°å¯ä»¥ç¡®ä¿ä¸æ ä¸å¤±
QByteArray buffer = QString("xxx").toUtf8();
const char *text = buffer.constData();
test(text);
//å¯ä»¥ç´æ¥ä½ä¸ºåæ°ä¼ å
¥ä¹æ¯æ£ç¡®ç
test(QString("xxx").toUtf8().constData());
- å ³äºæ¯ä½¿ç¨QListè¿æ¯QVectorçé®é¢ï¼ä¸ç´æ¯ä¼å¤Qterçéæ©é®é¢ï¼ä¸»è¦æ¯è¿ä¸¤ä¸ªç©ææä¾ççæ¥å£å½æ°åºæ¬ä¸è´ï¼æ¯å¦æå ¥ãå é¤ãåå¼çã
- 大å¤æ°æ åµä¸å¯ä»¥ç¨QListãåappendãprependãinsertè¿ç§æä½ï¼é常QListæ¯QVectorå¿«çå¤ã
- QListæ¯åºäºindexæ ç¾åå¨å®çå ç´ é¡¹å¨å åä¸ï¼æ¯é£ç§ä¾èµiteratorè¿ä»£çæ´å¿«æ·ï¼èä¸ä½ ç代ç ä¹æ´å°ã
- å¦æä½ éè¦ä¸ä¸ªçæ£çè¿æ¥ççlistï¼ä¸éè¦ä¿è¯ä¸ä¸ªåºå®æå ¥èæ¶ãé£å°±ç¨è¿ä»£å¨ï¼èä¸æ¯æ ç¾ã使ç¨QLinkedList()ã
- å¦æä½ éè¦å¼è¾è¿ç»çå å空é´åå¨ï¼æè ä½ çå ç´ è¿æ¯ä¸ä¸ªæé大ï¼è¿æ¶ä½ éè¦é¿å 个å«æå ¥æä½ï¼åºç°å æ 溢åºï¼è¿æ¶åç¨QVectorã
- å¦ææ´å¨æåå¼çé度åç¨QVectorï¼QCustomPlotç¨çå°±æ¯QVectorï¼éè¦é¢ç¹å¤§éçååºæ°æ®è¿è¡ç»å¶ã
- å¦ææ´å¨ææ´æ°æ°æ®ï¼æ·»å ãå é¤çï¼çé度åç¨QListï¼å¯¹åºæä½æ¯[]=å¼ï¼ï¼ä½æ¯å 为QChart主è¦ç¨çæ¯QList访é®æ°æ®ï¼å¯¹åºæä½æ¯at()ï¼ï¼ä¹æ¯å¯¼è´å¤§æ°æ®éå¡é¡¿çåå ä¹ä¸ï¼ä¸ç´è¢«è¯ç ã
- æ²çº¿å¾è¡¨è¿ç±»çåºæ¬ä¸ç»å¤§é¨åæ¶é´é½æ¯å¨è®¿é®æ°æ®ï¼æ¿å°è®¾ç½®å¥½çæ°æ®è¿è¡ç»å¶ã
- æ»ä¹ï¼QListæ´æ°ï¼æå ¥ã追å çï¼æ°æ®é度快ï¼QVectoråæ°æ®é度快ã
- å¨æ°æ®éå¾å°çæ åµä¸ä¸¤è å ä¹æ²¡å¥æ§è½åºå«ã
- è²ä¼¼Qt6对è¿ä¸¤ä¸ªç±»å并äºï¼éæ©å°é¾ççQter解æ¾äºï¼ï¼QVector=QListå³QVectoræ¯QListçå«åï¼å¯è½åºå±æ¹äºä»£ç 以便åæ¥ä¸¤è çä¼å¿ã
- å ³äºmouseTrackingé¼ æ 追踪åtabletTrackingå¹³æ¿è¿½è¸ªçå ç¹å®æ¹è¯´æã
- mouseTrackingå±æ§ç¨äºä¿åæ¯å¦å¯ç¨é¼ æ è·è¸ªï¼ç¼ºçæ åµæ¯ä¸å¯ç¨çã
- 没å¯ç¨çæ åµä¸ï¼å¯¹åºé¨ä»¶åªæ¥æ¶å¨é¼ æ 移å¨åæ¶è³å°ä¸ä¸ªé¼ æ æé®æä¸æ¶çé¼ æ 移å¨äºä»¶ã
- å¯ç¨é¼ æ è·è¸ªçæ åµä¸ï¼ä»»ä½é¼ æ 移å¨äºä»¶é¨ä»¶é½ä¼æ¥æ¶ã
- é¨ä»¶æ¹æ³hasMouseTracking()ç¨äºè¿åå½åæ¯å¦å¯ç¨é¼ æ è·è¸ªã
- setMouseTracking(bool enable)ç¨äºè®¾ç½®æ¯å¦å¯ç¨é¼ æ è·è¸ªã
- ä¸é¼ æ è·è¸ªç¸å ³çå½æ°ä¸»è¦æ¯mouseMoveEvent()ã
- tabletTrackingå±æ§ä¿åæ¯å¦å¯ç¨é¨ä»¶çå¹³æ¿è·è¸ªï¼ç¼ºçæ¯ä¸èµ·ç¨çã
- 没æå¯ç¨å¹³æ¿è·è¸ªçæ åµä¸ï¼é¨ä»¶ä» æ¥æ¶è§¦æ§ç¬ä¸å¹³æ¿æ¥è§¦æè³å°æ个触æ§ç¬æé®æä¸æ¶ç触æ§ç¬ç§»å¨äºä»¶ã
- å¦æé¨ä»¶å¯ç¨äºå¹³æ¿è·è¸ªåè½ï¼é¨ä»¶è½æ¥æ¶è§¦æ§ç¬é è¿ä½æªçæ£æ¥è§¦å¹³æ¿æ¶ç触æ§ç¬ç§»å¨äºä»¶ã
- è¿å¯ä»¥ç¨äºçè§æä½ä½ç½®ä»¥åé¨ä»¶çè¾ å©æä½åè½ï¼å¦æ转åå¾æï¼ï¼å¹¶ä¸ºå¾å½¢çé¢æä¾è¿äºæä½çä¿¡æ¯æ¥å£ã
- é¨ä»¶æ¹æ³hasTabletTracking()ç¨äºè¿åå½åæ¯å¦å¯ç¨å¹³æ¿è·è¸ªã
- setTabletTracking(bool enable)ç¨äºè®¾ç½®æ¯å¦å¯ç¨å¹³æ¿è·è¸ªã
- ä¸å¹³æ¿è·è¸ªç¸å ³çå½æ°ä¸»è¦æ¯tabletEvent()ã
- å ³äºQTableWidgetçæ§ä»¶è°ç¨èªå¸¦çremoveRowãclearContentsãclearå½æ°å é¤äºéé¢çitemåå 容ï¼ä¼èªå¨è°ç¨itemæè cellwidgetçææå½æ°è¿è¡èµæºéæ¾ï¼ä¸ç¨èªå·±æå¨åå»éæ¾ã
//æ¯æ¬¡è°ç¨ clearContents é½ä¼èªå¨æ¸
çä¹åçitem
ui->tableWidget->clearContents();
for (int i = 0; i < count; ++i) {
ui->tableWidget->setItem(i, 0, new QTableWidgetItem("aaa"));
ui->tableWidget->setItem(i, 1, new QTableWidgetItem("bbb"));
ui->tableWidget->setCellWidget(i, 2, new QPushButton("ccc"));
}
- 对äºQListViewï¼QListWidgetï¼ãQTreeViewï¼QTreeWidgetï¼ãQTableViewï¼QTableWidgetï¼è¿ç§ç±»åçæ§ä»¶ï¼å¯ä»¥éè¿setCheckedæ¥è®©å¯¹åºçitem产çå¤éæ¡ææï¼å¾å¤äººï¼å æ¬æ¾ç»çèªå·±ï¼è¯¯ä»¥ä¸ºè¿å°±æ¯å¤éæ¡æ§ä»¶ï¼å ¶å®ä¸æ¯çï¼ä»æ¯å¯¹åºæ§ä»¶çindicatoræ示å¨ï¼æ以æ³è¦æ´æ¢æ ·å¼ï¼ä¸è½è¯´è®¾ç½®äºQCheckBoxçæ ·å¼å°±æææï¼èè¦åç¬å¯¹é½indicatoræ示å¨è®¾ç½®æ ·å¼æè¡ã
QCheckBox::indicator,QGroupBox::indicator,QTreeWidget::indicator,QListWidget::indicator{
width:13px;
height:13px;
}
QCheckBox::indicator:unchecked,QGroupBox::indicator:unchecked,QTreeWidget::indicator:unchecked,QListWidget::indicator:unchecked{
image:url(:/qss/flatwhite/checkbox_unchecked.png);
}
QCheckBox::indicator:unchecked:disabled,QGroupBox::indicator:unchecked:disabled,QTreeWidget::indicator:unchecked:disabled,QListWidget::indicator:disabled{
image:url(:/qss/flatwhite/checkbox_unchecked_disable.png);
}
QCheckBox::indicator:checked,QGroupBox::indicator:checked,QTreeWidget::indicator:checked,QListWidget::indicator:checked{
image:url(:/qss/flatwhite/checkbox_checked.png);
}
QCheckBox::indicator:checked:disabled,QGroupBox::indicator:checked:disabled,QTreeWidget::indicator:checked:disabled,QListWidget::indicator:checked:disabled{
image:url(:/qss/flatwhite/checkbox_checked_disable.png);
}
QCheckBox::indicator:indeterminate,QGroupBox::indicator:indeterminate,QTreeWidget::indicator:indeterminate,QListWidget::indicator:indeterminate{
image:url(:/qss/flatwhite/checkbox_parcial.png);
}
QCheckBox::indicator:indeterminate:disabled,QGroupBox::indicator:indeterminate:disabled,QTreeWidget::indicator:indeterminate:disabled,QListWidget::indicator:indeterminate:disabled{
image:url(:/qss/flatwhite/checkbox_parcial_disable.png);
}
- å ³äºQTableViewï¼éç¨modelæ°æ®æºï¼ãQTableWidgetååå宽设置ï¼ææ¶ååç°æ²¡æèµ·ä½ç¨ï¼åæ¥æ¯å¯¹ä»£ç 设置ç顺åºæè¦æ±ï¼æ¯å¦setColumnWidthåå¿ é¡»å setColumnCountï¼ä¸ç¶åæ°é½æ²¡æï¼åªæ¥çå宽ï¼å æ¬setHorizontalHeaderLabels设置åæ é¢éåä¹æ¯ï¼åæé½è¦å æåã
void frmSimple::initForm()
{
//å®ä¾åæ°æ®æ¨¡å
model = new QStandardItemModel(this);
//设置è¡æ°åæ°
row = 100;
column = 10;
//设置ååå宽
for (int i = 0; i < column; ++i) {
columnNames << QString("å%1").arg(i + 1);
columnWidths << 60;
}
}
void frmSimple::on_btnLoad1_clicked()
{
//å
设置æ°æ®æ¨¡å,å¦å setColumnWidth ä¸èµ·ä½ç¨
ui->tableView->setModel(model);
//设置åæ°ååæ é¢åå宽
model->setColumnCount(column);
//ç®ä¾¿æ¹æ³è®¾ç½®åæ é¢éå
model->setHorizontalHeaderLabels(columnNames);
for (int i = 0; i < column; ++i) {
ui->tableView->setColumnWidth(i, columnWidths.at(i));
}
//循ç¯æ·»å è¡æ°æ®
QDateTime now = QDateTime::currentDateTime();
model->setRowCount(row);
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
QStandardItem *item = new QStandardItem;
//æåä¸åæ¾ç¤ºæ¶é´åºå«å¼æ¥
if (j == column - 1) {
item->setText(now.addSecs(i).toString("yyyy-MM-dd HH:mm:ss"));
} else {
item->setText(QString("%1_%2").arg(i + 1).arg(j + 1));
}
model->setItem(i, j, item);
}
}
}
void frmSimple::on_btnLoad2_clicked()
{
//设置åæ é¢ååæ°åå宽
ui->tableWidget->setColumnCount(column);
//ç®ä¾¿æ¹æ³è®¾ç½®åæ é¢éå
ui->tableWidget->setHorizontalHeaderLabels(columnNames);
for (int i = 0; i < column; ++i) {
ui->tableWidget->setColumnWidth(i, columnWidths.at(i));
}
//æ·»å æ°æ®
QDateTime now = QDateTime::currentDateTime();
ui->tableWidget->setRowCount(row);
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
QTableWidgetItem *item = new QTableWidgetItem;
//æåä¸åæ¾ç¤ºæ¶é´åºå«å¼æ¥
if (j == column - 1) {
item->setText(now.addSecs(i).toString("yyyy-MM-dd HH:mm:ss"));
} else {
item->setText(QString("%1_%2").arg(i + 1).arg(j + 1));
}
ui->tableWidget->setItem(i, j, item);
}
}
}
20ï¼191-200
- å ³äºQListéåçå¤çä¸ï¼æ们æ常ç¨çå°±æ¯è°ç¨appendå½æ°æ·»å itemï¼å¾åæå ¥itemå¾å¤äººç¬¬ä¸å°è±¡å°±æ¯è°ç¨insert(0,xxx)æ¥æå ¥ï¼å ¶å®QListå®å ¨æä¾äºå¾å追å itemçå½æ°prependãpush_frontã
QStringList list;
list << "aaa" << "bbb" << "ccc";
//å¾å追å çä»·äº append
list.push_back("ddd");
//å¾å追å çä»·äº prepend
list.push_front("xxx");
//å¾å追å
list.append("ddd");
//å¾å追å
list.prepend("xxx");
//æå®ç¬¬ä¸ä¸ªä½ç½®æå
¥ çä»·äº prepend
list.insert(0, "xxx");
//è¾åº QList("xxx", "aaa", "bbb", "ccc", "ddd")
qDebug() << list;
- Qtå ç½®äºä¸äºQListãQMapãQHashç¸å ³çç±»åï¼å¯ä»¥ç´æ¥ç¨ï¼ä¸ç¨èªå·±å个é¿é¿çç±»åã
//qwindowdefs.h
typedef QList<QWidget *> QWidgetList;
typedef QList<QWindow *> QWindowList;
typedef QHash<WId, QWidget *> QWidgetMapper;
typedef QSet<QWidget *> QWidgetSet;
//qmetatype.h
typedef QList<QVariant> QVariantList;
typedef QMap<QString, QVariant> QVariantMap;
typedef QHash<QString, QVariant> QVariantHash;
typedef QList<QByteArray> QByteArrayList;
-
Qtçå¸å±çè¾¹è·é´éï¼å¦æå¨æ²¡ææ¹å¨è¿çæ åµä¸ï¼æ¯ä¼æ ¹æ®ç³»ç»å辨ç以å缩æ¾æ¯æ¥å³å®å¯¹åºçé»è®¤å¼ï¼æ¯ååçï¼æ¯å¦å¨1080På辨çæ¯9pxï¼å¨2Kå辨çååæäº11pxï¼ææä½ ä¼åç°ä½ å¨1080Pçµèç¼è¯çç¨åºï¼ææçå°çæ¯6pxã9pxï¼æä¹å°2Kã4Kå辨çä¸é´éåè¾¹è·å°±åå¾å¥½å¤§ï¼å¦æè¦ä¿ææ 论ä½ç§å辨çé½ä¸æ ·ï¼ä½ éè¦æå¨éæ°è®¾ç½®è¿äºå¼ï¼è¿éæ个åï¼æ¯å¦é»è®¤æ¯æ¯9ï¼ä½ æ³å ¶ä»å辨çä¹æ¯9ï¼ä½ å¿ é¡»å æ9æ¹æå ¶ä»å¼æ¯å¦10ï¼ç¶ååæ¹æ9ï¼è¿æ ·æ表示ççæ¹å¨ï¼ä½ ç´æ¥9æ¹æ9æ¯ä¸ä¼ååçï¼å¨å±æ§è®¾è®¡å¨ä¸å³ä¾§æ个å°ç®å¤´æ¢å¤å¼çï¼ä¹æ¯ç°è²ï¼åªæå æ·±æ¾ç¤ºï¼å¹¶ä¸åºç°äºæ¢å¤é»è®¤å¼ç®å¤´ï¼æè¡¨ç¤ºä½ ç¡®å®æ¯æ¹è¿äºå¼ã
-
Qt对é«åå±ä»¥ådpi缩æ¾çæ¯æè¶æ¥è¶æçï¼å¨Qt4æ¶ä»£é»è®¤ççç¥å°±æ¯è·éç³»ç»ç缩æ¾ï¼ä»Qt5.6å¼å§æä¾äº AA_EnableHighDpiScaling çå±æ§è®¾ç½®å¼å¯é«åå±ï¼å°äº5.14以åè¿å¯ä»¥æå®ç¼©æ¾ççç¥ HighDpiScaleFactorRoundingPolicy æ¯å¦æ¯ææµ®ç¹æ°ç缩æ¾æ¯èä¸æ¯ä¹åçæ´æ°åï¼ä»Qt6å¼å§é»è®¤æ°¸è¿å¼å¯äº AA_EnableHighDpiScaling å±æ§ï¼æ²¡æ³åæ¶ãå¾å¤æ¶åæ们éè¦ä¸¤ç§æ¨¡å¼ï¼ä¸ç§å°±æ¯æ°¸è¿ä¸åºç¨é«åå±å缩æ¾ï¼ä¸ç§å°±æ¯èªå¨åºç¨é«åå±å缩æ¾ã
//æ°¸è¿ä¸åºç¨é«åå±å缩æ¾
int main(int argc, char *argv[])
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QApplication::setAttribute(Qt::AA_Use96Dpi);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
QApplication a(argc, argv);
....
return a.exec();
}
//èªå¨åºç¨é«åå±å缩æ¾
//æ¹æ³å¾å¤ï¼ç»¼å对æ¯ä¸æ¥è¿æ¯éç¨é
ç½®æ件æå®ç¼©æ¾çç¥æéä¸ã
//æ°å»ºqt.confæ件æ¾å°å¯æ§è¡æ件åä¸ç®å½
[Platforms]
WindowsArguments = dpiawareness=0
//ææ¶åæ³è®©ç¨æ·å»éæ©ä½ç§çç¥ï¼éè¦å¼å¯é«åå±çä¹ååªéè¦å°qt.confæ件æ¾å°å¯æ§è¡æ件åä¸ç®å½å³å¯ï¼å°±ç®ä»£ç ä¸è®¾ç½®äºä¸åºç¨é«åå±å缩æ¾ï¼ä¹æ æï¼ä¹æ¯ä¼å
åqt.confæ件ççç¥ã
- å ³äºQSSè¦æ³¨æçåã
- qssæºèªcssï¼ç¸å½äºcssçä¸ä¸ªåéï¼ä¸»è¦æ¯æçæ¯css2æ åï¼å¾å¤ç½ä¸çcss3çæ åçåæ³å¨qssè¿éæ¯ä¸çæçï¼æ以ä¸è¦å¤§æå°æªã
- qssä¹ä¸æ¯å®å ¨æ¯æææçcss2ï¼æ¯å¦text-alignå®æ¹æ档就æ说æï¼åªæ¯æ QPushButton and QProgressBarï¼å¡å¿ çæ¸ æ¥ã
- ææ¶åå·æç´æ¥æ¥ä¸å¥ *{xxx}ï¼ä½ ä¼åç°å¤§é¨åæ¯åºç¨äºï¼ä¹æå°é¨åæè æ个å«æ²¡æåºç¨ï¼ä½ å¯è½éè¦å¨å¯¹åºççªä½ä¸ this->setStyleSheet() æ¥è®¾ç½®ã
- qssçæ§è¡æ¯æä¼å 级çï¼å¦æ没ææå®ç¶å¯¹è±¡ï¼å对ææçåºç¨ï¼æ¯å¦å¨çªä½widgetä¸ {color:#ff0000;} è¿æ ·ä¼å¯¹widget以åwidgetçææå对象åºç¨è¯¥æ ·å¼ï¼è¿ç§é®é¢å大群æ¯å¨é½æ人é®ï¼ä½ ä¼åç°åç§å¥å¥æªæªçå¼æ ·ä¸æ£å¸¸ï¼æä¹åå¢ï¼ä½ éè¦æå®ç±»åæè 对象åï¼æ¯å¦ #widget{color:#ff0000;} è¿æ ·å°±åªä¼å¯¹widget对象åºç¨è¯¥æ ·å¼ï¼å¦ä¸ç§åæ³ QWidget#widget{color:#ff0000;}ï¼åªæ³å¯¹çªä½æ¬èº«èä¸æ¯åæ§ä»¶æé®æ ç¾ç .QWidget{color:#ff0000;} ï¼å ·ä½è¯¦ç»è§ååè§å®æ¹è¯´æã
- qssæ´ä½æ¥è¯´è¿æ¯å¯ä»¥çï¼è§£æé度æ§è½å¨Qt5é«çæ¬åææ¯Qt4好å¾å¤ï¼å°¤å ¶æ¯ä¿®å¤äºä¸å°qssä¸ç解æç»å¶BUGã尽管æè¿æ ·é£æ ·çBUGï¼æçå 容çå¿å¯¹å¾ å®ã
- qsså®æ¹å¦ä¹ å°å1ï¼http://47.100.39.100/qtwidgets/stylesheet-reference.html
- qsså®æ¹å¦ä¹ å°å2ï¼http://47.100.39.100/qtwidgets/stylesheet-examples.html
- å ³äºQt延æ¶çå ç§æ¹æ³ã
void QtHelperCore::sleep(int msec)
{
if (msec <= 0) {
return;
}
#if 1
//éé»å¡æ¹å¼å»¶æ¶,ç°å¨å¾å¤äººæ¨èçæ¹æ³
QEventLoop loop;
QTimer::singleShot(msec, &loop, SLOT(quit()));
loop.exec();
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
//é»å¡æ¹å¼å»¶æ¶,å¦æå¨ä¸»çº¿ç¨ä¼å¡ä½ä¸»çé¢
QThread::msleep(msec);
#else
//éé»å¡æ¹å¼å»¶æ¶,ä¸ä¼å¡ä½ä¸»çé¢,æ®è¯´å¯è½æé®é¢
QTime endTime = QTime::currentTime().addMSecs(msec);
while (QTime::currentTime() < endTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
#endif
#endif
}
- éçå½äº§åçå ´èµ·ï¼åç§å½äº§ç³»ç»åå½äº§æ°æ®åºçéæ¸è¿å ¥å¼åè çä¸çï¼ç½åå 个è¦ç¹ã
- ä¸æ éºéºneokylinåºäºcentosã
- é¶æ²³éºéºkylinæ©æçæ¬æ¯å¦V2åºäºfreebsdï¼æ°çæ¬V4ãV10åºäºubuntuã
- ä¼éºéºubuntukylinå°±æ¯ubuntuçæ±åçæ¬ï¼å äºç¹ååæ§ä»¶å¥çã
- deepinåºäºdebianã
- uosåºäºdeepinæè 说æ¯deepinçåä¸åæ¯ã
- ubuntuåºäºdebianã
- linuxç主è¦å两ç§åè¡çæ¬ï¼debianï¼ubuntuãdeepinãuosãé¶æ²³éºéºkylinçï¼åredhatï¼fedoraãcentosãä¸æ éºéºneokylinãä¸å ´æ°æ¯ç¹newstartçï¼ï¼åå«å¯¹åºapt-getåyumå®è£ å½ä»¤ãç»å¤§é¨åçlinuxç³»ç»é½åºäºæè è¡çèªè¿ä¸¤ç§åè¡çæ¬ã
- ç论ä¸åºäºåä¸ç§ç³»ç»å æ ¸çï¼å¨å ¶ä¸ç¼è¯çç¨åºå¯ä»¥æ¢å°å¦å¤çç³»ç»è¿è¡ï¼åææ¯ç¼è¯å¨çæ¬ä¸è´ï¼æ¯å¦é½æ¯gcc4.9ï¼å¨ubuntu14.04 64ä½ç¨gcc4.9ç¼è¯çQtç¨åºï¼æ¯è½å¤å¨uos 64ä½ä¸è¿è¡çã
- é«çæ¬ç¼è¯å¨çç³»ç»ä¸è¬è½å¤å ¼å®¹ä½çæ¬çï¼æ¯å¦ä½ ç¨gcc4.9ç¼è¯çç¨åºæ¯è½å¤å¨gcc7.0ä¸è¿è¡ï¼åè¿æ¥ä¸è¡ã
- æå³çå¦æä½ æ³å°½å¯è½å ¼å®¹æ´å¤çç³»ç»ï¼å°½éç¨ä½çæ¬çç¼è¯å¨ç¼è¯ä½ çç¨åºï¼å½ç¶è¦ä½ çç¨åºä»£ç è¯æ³æ¯æï¼æ¯å¦c++11å°±è¦ä»gcc4.7å¼å§ææ¯æï¼å¦æä½ ç代ç ç¨äºc++11åå¿ é¡»è³å°éæ©gcc4.7çæ¬å以ä¸ã
- ç¨Qtç¼ålinuxç¨åºä¸ºäºåå¸åçå¯æ§è¡æ件å¯ä»¥å ¼å®¹åç§linuxç³»ç»ï¼åªè¦å¨è¿ä¸¤ç§å æ ¸ï¼debianãredhatï¼çç³»ç»ä¸ç¨ä½çæ¬çç¼è¯å¨æ¯å¦gcc4.7ç¼è¯qtç¨åºåå¸å³å¯ã
- 2022-01-27è¡¥å ï¼æ ¹æ®Qtå®æ¹å®è£ å ï¼å ³äºå¯¹è¯æ¡ï¼ï¼åç°åºäºredhatågcc4.9ï¼åé¢Qt5.14/5.15带çqtcéç¨gcc5.3ï¼ç¼è¯å¨åå¸çï¼éç¨åç§linuxç³»ç»ï¼äº²æµubuntuå个çæ¬ãfedoraãcentosãdeepinãuosãé¶æ²³éºéºkylinãä¸æ éºéºneokylinãä¸å ´æ°æ¯ç¹newstartçï¼ï¼èªå·±æç §è¿ä¸ªçæ¬ä¹äº²æµæå åå¸äºï¼äº²æµå¯ç¨ï¼ææ¦ï¼redhatç³»ç»çä¹å¯ä»¥å¨debianç³»ç»è·ã
- 2022-02-10è¡¥å ï¼debianä¸éæç¼è¯çç¨åºä¹å¯ä»¥å¨redhatç³»ç»è·ï¼å¯è½éæç¼è¯å»æäºå¾å¤ä¾èµå§ã
- 2022-03-01è¡¥å ï¼ä½è°å¤§ä½¬è¡¥å ï¼å¦æ没æç¹å®çä¾èµå ³ç³»ï¼é«çæ¬çç¼è¯å¨ç¼è¯çç¨åºä¹å¯ä»¥å¨ä½çæ¬ç¼è¯å¨çç³»ç»è¿è¡ï¼æ¯å¦alpine Linuxä¸ç¨gcc11/clang13ç¼è¯çæçå¯æ§è¡äºè¿å¶ï¼ä¾ç¶å¯ä»¥å¨cenos5/ubuntu10ä¸è¿è¡ã并ä¸æ¯ç¼è¯å¨çæ¬çé®é¢ï¼ä¹ä¸æ¯C++11ç¹æ§çé®é¢ï¼è¿ä¸ªé®é¢æ¶åå°å¤ªå¤ï¼å æ ¸çæ¬ãgnu libcãABIå ¼å®¹ççï¼ä¸¤å¥è¯è¯´ä¸æ¸ ã
- æç §QtCreator软件éç¨çç¼è¯å¨ç¯å¢è§åï¼ä¸è¬æ¥è¯´å°±æ¯ä½çæ¬çå¯ä»¥å¨é«çæ¬è¿è¡ï¼æ¯å¦Qt5å¯ä»¥å¨ubuntu14/16/18/20è¿è¡ï¼ä½æ¯é«çæ¬ç¼è¯å¨ç¼è¯çå°±æ æ³å¨ä½çæ¬ç¼è¯å¨ç³»ç»è¿è¡ï¼ä¼æ示缺å°GLBCãLIBCXXãsymbol xxxxxxçï¼æ¯å¦Qt6å¯ä»¥å¨ubuntu20è¿è¡èæ æ³å¨ubuntu18/16/14çè¿è¡ã
- å¨uosä¸åå¼åï¼å»ºè®®éç¨ç³»ç»èªå¸¦çQtåºç¯å¢å¼åï¼ä»¥åå½ä»¤è¡å®è£ å¼åç¯å¢ï¼ä¸å»ºè®®ä½¿ç¨Qtå®æ¹çå®è£ å æ建ç¯å¢ï¼å 为uosçQtæ¯éæ¹è¿çï¼ç¨Qtå®æ¹çæ åå®è£ å çç¯å¢å¼ååºæ¥çç¨åºï¼æå åå¸å¾å¯è½ä¼æä¾èµé®é¢èæ æ³è¿è¡ï¼èç¨ç³»ç»èªå¸¦çå°±ä¸åå¨è¿ä¸ªé®é¢ã
- å½äº§äººå¤§éä»æ°æ®åºç¨çæ¯postgresqlæ°æ®åºæ¹çï¼æå³çä½ å¨Qtä¸ç¨postgresqlæ°æ®åºæ件ä¹æ¯è½å¤è¿æ¥å°äººå¤§éä»æ°æ®åºçã
- 以ä¸æªå¿ å®å ¨æ£ç¡®ï¼æ¬¢è¿åä½ææ£ã
-
纵è§Qtçåå±åå²ï¼ä¹å ä¹ç»åçåä¹ å¿ åãåä¹ å¿ åçé»è¾ï¼æ¯å¦æå¼å§QPushButtonçUIæ§ä»¶ç±»é½æ¯å¨QtGui模åä¸ï¼åé¢è¶åèè¿ä¸æ¹ä¾¿ç®¡çåå级è¿ä»£ï¼åå离åºä¸ä¸ªQtWidgets模åï¼å°Qt6åå°QListåQVectorå并äºæäºä¸ä¸ªç±»ï¼æå¾ååä¹ å¿ åï¼èä¸ä¸äºæ°å¦å½æ°ä»¥åå°è£ çc++æ åå½æ°åºçæ¹æ³ï¼éæ¸æ¾å¼äºQtèªå·±çå°è£ æ¹ç¨c++æ åå½æ°åºï¼ä»å¼å§çåå°ç°å¨çåç»ä¸ã
-
Qtä¸ç´å¨æç»å级è¿ä»£ï¼å°½ç®¡æ°å¢å ç代ç è´¨éææ¾ä¸å¦è¯ºåºäºæ¶ä»£ï¼ä½æèµ·ç æè¡å¨ï¼æ ¢æ ¢å®åãç®å主è¦çå级æ¹åå¨qml模åï¼åºå±ä¹æå®åï¼æ¯ç«æ 论æ¯widgetè¿æ¯qmlé½æ¯å ¬ç¨ä¸å¥åºå±é»è¾ç±»ï¼åºå±åºç¡ä¸å®è¦æå®ç¨³åºï¼ä¸ªäººè¿å å¹´ä¸ç´å¯¹æ¯æµè¯è¿ä¸åQtçæ¬ï¼ä»æ§çæ¬å°æ°çæ¬ï¼å¾å¤ç±»åå½æ°çæ§è½ï¼åç°å®ç½ååºæ¥çæ°çæ¬å¯¹åºç±»åæ¹æ³çæ§è½æåæ¹åï¼ç¡®å®æ²¡æ说è°ï¼è³äºæåäºå¤å°è¿åæ没æå¹çé¼é£å°±ä¸æ¸ æ¥ã
- base64ç®æ³æ§è½æåå¾å¤§ã
- QStringListçå¡æ¯ä½¿ç¨äºQListç¸å ³çç±»ï¼æ§è½æå巨大ã
- 对æ¯æµè¯å¤§æ¦ä»5.12çæ¬å¼å§QStringListåQMapæ§è½ç¸å½ã
- æ©æçæ¬QStringListå¦ææ¥æ¾çå¼å æå ¥åæ¶é´è¶çï¼QMapå没æè¿ä¸ªåºå«ã
QStringList list1, list2;
QMap<QString, QString> map;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
for (int i = 0; i < 100000; ++i) {
QString s1 = QString("%1").arg(i);
QString s2 = QString("A%1").arg(i);
list1 << s1;
list2 << s2;
map.insert(s1, s2);
}
}
void MainWindow::on_pushButton_clicked()
{
QElapsedTimer time;
time.start();
qDebug() << "111" << time.nsecsElapsed() << list2.at(list1.indexOf("9999"));
}
void MainWindow::on_pushButton_2_clicked()
{
QElapsedTimer time;
time.start();
qDebug() << "222" << time.nsecsElapsed() << map.value("9999");
}
- å ³äºQtCreatorä¸ä¸ç§ä¸åç¼è¯çæ¬ debugãreleaseãprofile çåºå«ã
- debugè°è¯æ¨¡å¼ï¼ç¼è¯åçå¯æ§è¡æ件å¾å¤§ï¼å¸¦äºå¾å¤è°è¯ç¬¦å·ä¿¡æ¯çï¼æ¹ä¾¿å¼åé¶æ®µè°è¯çæ¶åè¿å ¥å ·ä½çå æ æ¥çå¼ãä¼æå¼ææçæè¨ï¼è¿è¡é¶æ®µæ§è½å·®éåº¦æ ¢ï¼å¯è½ä¼æå¡é¡¿æè§ã
- releaseåå¸æ¨¡å¼ï¼ç¼è¯åçå¯æ§è¡æ件å¾å°ï¼ä¸å¸¦ä»»ä½è°è¯ç¬¦å·ä¿¡æ¯ï¼ä¸è¬ç¨äºæå åå¸ç¨åºãç±äºç»è¿äºåç§ä¼åï¼ä¼å ³éæææè¨ï¼è¿è¡é¶æ®µæ§è½æ好ï¼å¦ææå¡é¡¿é£è¯å®æ¯ä½ çç¨åºé®é¢ã
- profileæ¦è¿°æ¨¡å¼ï¼ç¼è¯åçå¯æ§è¡æ件æ¯debugå°å¾å¤æ¯release大ä¸ç¹ï¼å¸¦æé¨åè°è¯ç¬¦å·ä¿¡æ¯ï¼å¨debugåreleaseä¹é´åä¸ä¸ªå¹³è¡¡ï¼å ¼é¡¾æ§è½åè°è¯ï¼æ§è½æ´ä¼ä½æ¯åæ¹ä¾¿è°è¯ã
- 使ç¨Qt5.7çæ¬å¯¹åºä¸ç§æ¨¡å¼ç¼è¯ç空ç½çªä½ç¨åºå¤§å°ï¼debugï¼1319kbï¼ãreleaseï¼24kbï¼ãprofileï¼90kbï¼ã
- debugé¾æ¥çåºæ¯å¸¦dç»å°¾çï¼releaseåprofileé¾æ¥çåºæ¯ä¸å¸¦dç»å°¾çï¼å¾å¤äººä»¥ä¸ºprofileé¾æ¥çæ¯å¸¦dç»å°¾çå ¶å®æ¯é误çã
- æ°çQtå¨çº¿å®è£ ç¨åºå¨å®è£ çæ¶åï¼å¯ä»¥å¾éæ¯å¦å®è£ debugè°è¯åºï¼å¯¹åºlibç®å½ä¸ä¸å 带dç»å°¾çæ件ï¼ï¼ä»¥åççæ¬æ¯é»è®¤é½å®è£ ï¼ç°å¨å¯éå®è£ 以便åå°ä½ç§¯ã
- æ 论æ¯å¦å®è£ äºdebugè°è¯åºï¼ä½ é½å¯ä»¥éæ©debug模å¼çæ对åºdebugçæ件ï¼è¿ä¸ªä¸ç¥éæä¹åå°çã
- æ 论æ¯åªç§æ¨¡å¼ï¼é½å¯ä»¥å¨ç¨åºä¸å¼å¯æ¥å¿é©åè¾åºæ¥å¿ä¿¡æ¯ï¼æ¹ä¾¿æ¶éè¿è¡é¶æ®µçåç§ä¿¡æ¯åé¦ç»å¼å人åæ¥çé®é¢ã
- æåçå¼åå·¥å ·ä¸è¬æ¯å ·ædebugårelease两ç§æ¨¡å¼ï¼éçç¨æ·éæ±çå¢å ååºæ¯çéè¦ï¼é¨åå¼åå·¥å ·è¡çåºäºprofile模å¼ï¼æ´æçè æ¯å¦flutterè¿æ第åç§test模å¼ã
21ï¼201-210
- ç¼è¯çædebugçæ¬å¨æåºï¼æ件æ«å°¾èªå¨å ä¸dç»å°¾ã
CONFIG(debug, debug|release) {
win32: TARGET = $$join(TARGET,,,d)
mac: TARGET = $$join(TARGET,,,_debug)
unix:!mac: TARGET = $$join(TARGET,,,d)
}
#å¤æå½åå¥ä»¶æ¯debugè¿æ¯release
CONFIG(debug, debug|release) {}
CONFIG(release, debug|release) {}
- QtCreatorä¸pro项ç®æä»¶æ ¼å¼è¯´æã
å称 | 说æ |
---|---|
QT += core gui | æ·»å æ¬é¡¹ç®ä¸éè¦ç模åï¼å½±ååé¢ä»£ç æ件includeçæ¶åèªå¨å¼¹åºä¸æéæ©ï¼å¦æproæ件没æå¼å ¥è¯¥æ¨¡ååæ æ³èªå¨è¯æ³æ示ï¼ä¸è¬æå åå¸çæ¶å对åºå¨æåºæ件æ¯å¦ Qt5Core.dllã |
TARGET = xxx | çææåç®æ æ件çååï¼å¯ä»¥æ¯å¯æ§è¡æ件æè åºæ件ã |
TEMPLATE = app | 项ç®ç¨åºççæ模å¼ï¼é»è®¤æ¯app表示çæå¯æ§è¡æ件ç¨åºï¼å¦ææ¯å¨æåºé¡¹ç®å°±æ¯ TEMPLATE = libã |
CONFIG += qaxcontainer | å¼å ¥ä¸äºé ç½®ï¼å¨Qt4çæ¶åè¿ç¨æ¥å¼å ¥ä¸äºæ¨¡åï¼å ¶ä¸æé¨åæ¹æäºQT += æ¹å¼å¼å ¥ï¼æ¯å¦Qt5å¼å ¥æ¬å°activexæ§ä»¶æ¯ææ¹æäºQT += qaxcontainerã |
DEFINES += xxx | 项ç®ä¸èªå®ä¹çä¸äºå®ä¹ï¼å¯ä»¥å¨ä»£ç æ件ä¸è¯å«ï¼é常ç¨æ¥å®ä¹ä¸äºä¸åå¹³å°çå¤çï¼æ ¹æ®é¡¹ç®éè¦èªå·±å®ä¹ä»»ä½æ è¯ã |
HEADERS += head.h | 项ç®ä¸ç¨å°ç头æ件ï¼ä¸è¬æå±åæ¯.hï¼å¯ä»¥åå¨ä¸è¡ä¹å¯ä»¥åè¡åï¼åè¡è¦ç¨ \ ææ ç»æã |
SOURCES += main.cpp | 项ç®ä¸ç¨å°çå®ç°æ件ï¼ä¸è¬æå±åæ¯.cppï¼å¯ä»¥åå¨ä¸è¡ä¹å¯ä»¥åè¡åï¼åè¡è¦ç¨ \ ææ ç»æã |
FORMS += Form.ui | 项ç®ä¸ç¨å°çUIæ件ï¼ä¸è¬æå±åæ¯.uiï¼å¯ä»¥åå¨ä¸è¡ä¹å¯ä»¥åè¡åï¼åè¡è¦ç¨ \ ææ ç»æã |
RESOURCES += main.qrc | 项ç®ä¸ç¨å°çèµæºæ件ï¼å¯ä»¥å¤ä¸ªï¼å代ç 使ç¨å¯¹åºèµæºæ件ä¸çæ件æ¶åå¡å¿ è®°å¾èµæºæ件ä¸çåç¼ã |
LIBS += -L$$PWD/ -lavformat -lavcodec | 项ç®ä¸ç¼è¯æ¶åé¾æ¥ä¾èµçåºï¼ä¸è¬æ¯ .lib .a .dylib æ件ï¼å¯ä»¥åå¨ä¸è¡ï¼çç¥æ件åçlibæ头é¨åï¼ä¹å¯ä»¥åå¤è¡ç»å¯¹è·¯å¾åå ¨å称ã |
DESTDIR += $$PWD/bin | ç®æ çæè·¯å¾ï¼$$PWD表示å½åç®å½ï¼ä¸è¬å»ºè®®çæçæç»æ件éå®åå°å¦å¤ç®å½åæ¾ï¼å¥½æ¾ï¼ä¸ç¶ä¸å 临æ¶æ件å¨éé¢ææ¶åæ件太å¤å¥½é¾æ¾ã |
INCLUDEPATH += $$PWD/include | å·¥ç¨éè¦ç头æ件ï¼æå®æ´ä¸ªç®å½ï¼å代ç çæ¶åæ¾å°çè¯ä¼èªå¨ä¸æã |
DEPENDPATH += | å·¥ç¨çä¾èµè·¯å¾ï¼ç¨çæ¯è¾å°ï¼ä¸è¬æ¶åå°å¼å ¥é¾æ¥åºçæ¶åå¯è½éè¦ã |
include($$PWD/3rd.pri) | å¼å ¥pri模åæ件ï¼priæ大ç好å¤å°±æ¯åç®å½ç®¡çæ件ï¼éç¨çè½®å模åå¯ä»¥æ¾å°ä¸ä¸ªç®å½ä¸ï¼ç¶åç¨priç»ä¸ç®¡çï¼å¯ä»¥ç»å¤ä¸ªé¡¹ç®å ¬ç¨ã |
å®æ¹è¯¦ç»å°åhttps://doc.qt.io/qt-5/qmake-variable-reference.html
-
å¦æåç°ä¹åç¼è¯æ£å¸¸ï¼çªç¶ä¹é´åç¼è¯å°±ä¸ç´æ»å¾ªç¯çæ ·åï¼åçå¨ä¸è¡æ示并ç¯çä¸åçæå°ï¼æè æ示æ件æ¶é´å¨æªæ¥ï¼è¿è¯´æä½ å¾å¯è½æ¹è¿å¼åç¯å¢çæ¶é´ï¼æ¯å¦æµè¯æ个æææ件失æï¼ï¼å¯¼è´æä¿®æ¹è¿æ件çä¿åæ¶é´å¨æªæ¥ï¼ä½ åªéè¦å°æ¶é´è°æ´åæ¥ï¼å°æåæ´æ°æ¶é´ä¸æ£ç¡®ç代ç æ件éæ°ä¿åä¸å°±è¡ãQtçå¢éç¼è¯æ¯æ ¹æ®æ件çæåä¿®æ¹æ¶é´æ¥å¤å®çï¼æåçä¿®æ¹æ¶é´æ¯ä¸ä¸æ¬¡çä¿®æ¹æ¶é´è¿è¦æ°å认为该æ件被修æ¹è¿ï¼éè¦éæ°ç¼è¯è¯¥æ件ã
-
Qtçæ建å¥ä»¶ä¸è¬æ¯å¨å®è£ Qtå¼åç¯å¢çæ¶åèªå¨è®¾ç½®çï¼å½ç¶ä¹å¯ä»¥æå¨è®¾ç½®ï¼æå¨è®¾ç½®çæ¶ååä¸è¦æ³¨æç¼è¯å¨åQtåºå¿ é¡»ä¸è´ï¼å¦å该æ建å¥ä»¶æ¯æé®é¢çï¼åä¸ä¸è½ä¹±è®¾ç½®ï¼å°¤å ¶æ¯å¯¹æ建å¥ä»¶å½åçæ¶åæ好æ æqtçæ¬åç¼è¯å¨çæ¬ï¼æ好ä¹è¦ä¸è´ï¼ä¸è¦è¯´å称å«msvcèç¼è¯å¨éæ©çç¡®æ¯mingwï¼è¿æ ·å°½ç®¡è½æ£å¸¸ä½¿ç¨è¯¥æ建å¥ä»¶ï¼ä½æ¯ä¼é æä¸ç§è¯¯è§£ï¼è¿ä»¥ä¸ºè¯¥å¥ä»¶æ¯msvcçï¼å ¶å®éé¢æ¯mingwçãæ个qter说ä»çqtåäºï¼æ»æ´»ç¼è¯å¤±è´¥ï¼è¿ç¨ä¸çï¼å°¼çï¼æ建å¥ä»¶å称åçqt_msvc2019 ç¼è¯å¨éæ©çmsvc2015ï¼ä»çµèåªå®è£ äºvs2015ï¼ï¼qtåºéæ©çmingwï¼å·®ç¹çæèªå·±å «ä¸ªè³å ï¼å¤ªç¦»è°±äºï¼
-
å½ä½ ç¼è¯Qtç¨åºåç°ç¼è¯éä¸è¿æ示æ¥éï¼èä¸æ¥éæ示å¨Qtç头æ件çæ¶åï¼ä¸è¦å»å°è¯çä¿®æ¹Qt头æ件æ¥ç¼è¯éè¿ï¼é£æ ·æ²¡ç¨çï¼ä½ 使ç¨çQtçåºæ¯å·²ç»æ ¹æ®åå§ç头æ件ç¼è¯å¥½çãå¦ææ¥éæ示å¨ç¼è¯çæç临æ¶çmocçæ件ï¼ä½ ä¹ä¸è¦å°è¯å»ä¿®æ¹ä»ï¼é£ä¸ªæ¯ä¸´æ¶æ件ï¼è¿æ¬¡ä½ æ¹å¥½äºä¹è®¸ç¼è¯éè¿äºï¼ä½ éæ°ç¼ä¸ä¸åè¦çäºè¿æ¯æ§çé误ãæ»ä¹ä½ è¦ä»æºå¤´ï¼ä½ ç代ç ï¼æ¾é®é¢ã
-
ææ¶åéè¦å¯¹ææ¬è¿è¡åæ£å¯¹é½æ¾ç¤ºï¼ç¸å½äºæ 论æåå¤å°ï¼å°½å¯è½å 满æ´ä¸ªç©ºé´å¹³æå ä½å®½åº¦ï¼ä½æ¯å¨å¯¹æ¯æ对é½æ¹å¼çæ§ä»¶æ¯å¦QLabelè°ç¨ setAlignment(Qt::AlignJustify | Qt::AlignVCenter) 设置åæ£å¯¹é½ä¼åç°æ²¡æä»»ä½ææï¼è¿ä¸ªæ¶åå°±è¦èèå¦å¤çæ¹å¼æ¯å¦éè¿æ§å¶åä½çé´è·æ¥å®ç°åæ£å¯¹é½ææã
QString text = "æµè¯åæ£å¯¹é½å
容";
//计ç®å½åææ¬å¨å½ååä½ä¸å ç¨ç宽度
QFont font = ui->label->font();
int textWidth = ui->label->fontMetrics().width(text);
//æ¾ç¤ºææ¬çåºå宽度=æ ç¾ç宽度-两边çè¾¹è·
int width = ui->label->width() - 12;
//éè¦-1ç¸å½äºä¸é´æå 个é´é
int count = text.count() - 1;
//计ç®æ¯ä¸ªé´è·å¤å°
qreal space = qreal(width - textWidth) / count;
//设置åºå®é´è·
font.setLetterSpacing(QFont::AbsoluteSpacing, space);
ui->label->setFont(font);
ui->label->setText(text);
- éçéæ±çä¸æå¢å ï¼ç¨åºä¸æå大ï¼ç¨å°çå¨æåºä¹è¶æ¥è¶å¤ï¼å°äºåå¸ç¨åºçæ¶åä½ ä¼åç°åå¯æ§è¡æ件åä¸ç®å½ä¸æ件æ°éçå¤ï¼æ¤æ¶å¯è½ä¼èèå¦ä½å°ä¸äºåºæ件åé¨å«ç±»çåæ¾ï¼è¿æ ·æ¹ä¾¿ç®¡çã
- Qtæä¾ç设置å¨æåºè·¯å¾çæ¹æ³setLibraryPathsæ¯ç¨æ¥æç´¢æ件å¨æåºçï¼èä¸æ¯ç¨åºç´æ¥ä¾èµçå¨æåºã
- å¾å¤äººä»¥ä¸ºè¿ä¸ªå¯ä»¥è®¾ç½®Qtçåºæè ç¨åºä¸ä¾èµç第ä¸æ¹åºçè·¯å¾ï¼å ¶å®æ³æ³ä¹ç¥éï¼å 为ç¨åºä¾èµè¿ä¸ªåºï¼æ¾ä¸å°çè¯æ ¹æ¬è·ä¸èµ·æ¥ï¼ç¨åºè·ä¸èµ·æ¥æä¹åºç¨æ§è¡è¿ä¸ªä»£ç å¢ï¼
- Qté»è®¤æ¯å¯ç¨éè¿setLibraryPathsçæ¹å¼è®¾ç½®Qtæ件çå¨æåºç®å½ä½ç½®ï¼æ¯å¦æ°æ®åºæ件sqldriversï¼å 为è¿äºåºæ件æ¯çæ£å¨Qtç¨åºè·èµ·æ¥ä»¥åéè¿æ件形å¼å»å è½½çã
- è¿å¯ä»¥éè¿qt.confæ件设置 Plugins="config" æå®æææ件å¨å¯æ§è¡æ件ä¸çconfigç®å½ä¸ã
- è¦æ³è®¾ç½®ç¨åºç´æ¥ä¾èµçå¨æåºå¨å ¶ä»ç®å½ï¼æ¾éå ¨å®å®ä¹åªæä¸ä¸ªåæ³ï¼é£å°±æ¯è®¾ç½®ç¯å¢åéï¼é¤æ¤å«æ ä»æ³ã
- è³äºå¦ä½è®¾ç½®ç¯å¢åéæ¹å¼å¾å¤ï¼æ¯å¦æå¨å¨çµèä¸è®¾ç½®ï¼æè æ个æ¹å¤çæ件æ§è¡å½ä»¤è¡ï¼å¨ç¨åºå®è£ çæ¶åèªå¨æ§è¡ï¼æè ç¨åºæå ç®å½ä¸ç¨æ·æå¨è¿è¡è¿ä¸ªæ¹å¤çã
- 大ç¥è¡¥å ï¼è®¾ç½®æ件çç®å½è¿å¯ä»¥éè¿å¨mainå½æ°æåé¢å qputenv("PATH", QString("%1;%2").arg(qgetenv("PATH"), pluginFileInfo.path()).toLocal8Bit()); æ¥å®ç°ã
- ç½åè¡¥å ï¼æç»æ¾æ件çè·¯å¾å ¶å®å°±æ¯è¿ä¸ª QT_PLUGIN_PATH ç¯å¢åéã
-
è¿åº¦æ¡æ§ä»¶å¦æ设置çåç´æ¹åï¼å°±ç®ä½ 设置äºææ¬å¯è§ï¼ä¼åç°æ ¹æ¬çä¸å°è¿åº¦ææ¬ï¼ç»è¿å¤æ¹ç¾æä¸æ çè¯æ¢ï¼ä»¥ååé ·ç å¤§ä½¬æ·±å ¥çæ¢è®¨ï¼åç°åªè¦è®¾ç½®ä¸borderæ ·å¼ï¼border:1px solid #ff0000ãborder:noneãborder-style:solidãborder-radius:0px ä»»æä¸ç§ï¼å°±è¡ï¼å°±å¯ä»¥æææ¬æ¾ç¤ºåºæ¥ï¼è¿TMå°±ä¸ç¥éQt为ä»ä¹æ»æ¯ä¸ç»ä¸è§åï¼è¿ä¸ªBUGéç¨äºä»»ä½çæ¬ï¼è¿ä¸ªå¯è½æ¯å 为边æ¡çsolidæ ·å¼å²çªäºå¯¼è´æ æ³ç»§ç»ç»å¶ï¼ç¡®åç说è¿å¿ é¡»æ¯BUGï¼è¿ä¸ªé Qtå¿ é¡»èã
-
æ们å¨ä½¿ç¨QFileDialog::getOpenFileNameãQFileDialog::getExistingDirectoryçæ¹æ³æ¶ï¼ææ¶åä¼åç°é¦æ¬¡æå¼å¾å¡ï¼å°¤å ¶æ¯å¨é»è®¤ç®å½å¾å¤æ件çæ¶åï¼æ¤æ¶ä½ å¯ä»¥èè设置è¿äºå½æ°ææ«å°¾çåæ°ä¸ºQFileDialog::DontUseNativeDialogï¼è¡¨ç¤ºä¸éç¨æ¬å°ç³»ç»å¯¹è¯æ¡ï¼è¿æ ·çè¯ä¼éç¨Qtç对è¯æ¡ï¼é度快å¾å¤ï¼ä¼°è®¡ç³»ç»ç对è¯æ¡å¨æå¼çæ¶åä¼åå¾å¤åå§åå è½½å¤çã
QFileDialog::getOpenFileName(this, "", "", "", 0, QFileDialog::DontUseNativeDialog);
QFileDialog::getExistingDirectory(this, "", "", QFileDialog::DontUseNativeDialog);
- æ»åæ§ä»¶QSliderï¼å¦æ设置çåç´æ ·å¼ï¼å ¶è¿åº¦é¢è²åå©ä½é¢è²ï¼å好å横åæ ·å¼çé¢è²ç¸åçï¼ä¸ç¡®å®è¿ä¸ªæ¯å¦æ¯QtçBUGï¼Qt456é½æ¯è¿ä¸ªç°è±¡ã
QSlider::groove:horizontal{
height:8px;
background:#FF0000;
}
QSlider::add-page:horizontal{
height:8px;
background:#FF0000;
}
QSlider::sub-page:horizontal{
height:8px;
background:#00FF00;
}
QSlider::handle:horizontal{
width:10px;
background:#0000FF;
}
QSlider::groove:vertical{
width:8px;
background:#FF0000;
}
QSlider::add-page:vertical{
width:8px;
background:#00FF00;
}
QSlider::sub-page:vertical{
width:8px;
background:#FF0000;
}
QSlider::handle:vertical{
height:10px;
background:#0000FF;
}
22ï¼211-220
- QMainWindow å¨å¯¹åé çªä½è¿è¡æåçæ¶åï¼æäºä¸å¸¸ç¨ç设置容æéå¿ï¼å»ºè®®å° QMainWindow ç头æ件å½æ°è¿ä¸éä¸ç®äºç¶ã详ç»ä»ç»åç§åé åæ°æç« åè§ https://zhuanlan.zhihu.com/p/388544168ã
//设置å
许åç§åµå¥æ¯å¦ä¸ä¸æåå·¦å³æåé常çµæ´»
//æ¤è®¾ç½®ä¼åä¸é¢ç setDockOptions ä¸çåæ°è¦çæ以è¦æ³¨æ顺åº
//this->setDockNestingEnabled(true);
//设置åé åæ°,ä¸å
许éå ,åªå
许æå¨ååµå¥
this->setDockOptions(AnimatedDocks | AllowNestedDocks);
//å°åºé¨å·¦ä¾§ä½ä¸ºå·¦ä¾§åºåï¼åºé¨å³ä¾§ä½ä¸ºå³ä¾§åºåï¼å¦ååºé¨åºåä¼å¡«å
æ伸
this->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
this->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
- å½æ们å¨å¯¹QModelIndexåæ°æ®çæ¶åï¼å¸¸è§çè§è²çæ°æ®ï¼QVariantç±»åæ¯ætoçæ¯å¦toStringãtoIntãtoDoubleçï¼å¯ä»¥å¾æ¹ä¾¿çååºæ¥ï¼ç¹å®çæ°æ®ç±»åéè¦ç¨çä¸è½åå¼æ¨¡æ¿å½æ° T value() ååºæ¥ã
//æ¾ç¤ºææ¬
QString text = index.data(Qt::DisplayRole).toString();
//ææ¬å¯¹é½
int align = index.data(Qt::TextAlignmentRole).toInt();
//æååä½
QFont font = index.data(Qt::FontRole).value<QFont>();
//åæ¯è²
QColor color = index.data(Qt::ForegroundRole).value<QColor>();
//èæ¯è²
QColor color = index.data(Qt::BackgroundRole).value<QColor>();
- å¾å¤äººä»¥ä¸ºææ³åªè¦å¨dropEventäºä»¶å°±å¯ä»¥äºï¼å ¶å®ä¸è¡çï¼æ²¡æææçï¼éè¦å å¨dragEnterEventäºä»¶ä¸æ§è¡event->accept()æè¡ï¼ä¸ç¶æ ¹æ¬æ²¡æææï¼å¾å¤äººå°¤å ¶æ¯åå¦è é½æå¨è¿éï¼æå°±æ¯å¨è¿éæäºä¸è·¤ï¼å¥½ç¼ï¼
void frmMain::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
}
void frmMain::dragEnterEvent(QDragEnterEvent *event)
{
if(event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->ignore();
}
}
-
Qt5.6以åå ç½®çæ¯webengineæµè§å¨å æ ¸ï¼å¦æéè¦åweb交äºçè¯å¿ é¡»ç¨å° qwebchannel.js è¿ä¸ªæ件ï¼æ¤æ件æ¯Qtå®æ¹æä¾çï¼æ以ä¸å»ºè®®å»æ¹å¨å ¶ä¸çæºç ï¼è¦æ³¨æçæ¯ï¼ç±äºå®æ¹å¯¹webengineçæ¯æå¨ä¸ææ´æ°ï¼æ以å®æ¹æä¾ç对åºQtçæ¬ç qwebchannel.js æ件ä¹ä¸åï¼æå³çä½ è¦ç¨å¯¹åºæä¾ççæ¬ç qwebchannel.js æ件æokï¼è¯¥æ件é»è®¤å¨ C:\Qt\Qt5.12.11\Examples\Qt-5.12.11\webchannel\shared ç®å½ä¸ãç»è¿å å个Qtçæ¬çæµè¯åç°ï¼ç¨é«çæ¬ç qwebchannel.js æ¾å°ä½çæ¬è¿è¡ä¸è¡ï¼ä½çæ¬æ¾å°é«çæ¬å¯ä»¥ï¼ä¸ºäºä¸æ ä¸å¤±è¿æ¯å»ºè®®ç´æ¥ç¨å¯¹åºçæ¬çã
-
对äºQStringå»é¤ç©ºæ ¼ï¼æå¤ç§åºæ¯ï¼å¯è½éè¦å»é¤å·¦ä¾§ãå³ä¾§ãææçä½ç½®çç©ºæ ¼ã
//å符串å»ç©ºæ ¼ -1=移é¤å·¦ä¾§ç©ºæ ¼ 0=移é¤ææç©ºæ ¼ 1=移é¤å³ä¾§ç©ºæ ¼ 2=移é¤é¦å°¾ç©ºæ ¼ 3=é¦å°¾æ¸
é¤ä¸é´çä¸ä¸ªç©ºæ ¼
QString QtHelperData::trimmed(const QString &text, int type)
{
QString temp = text;
QString pattern;
if (type == -1) {
pattern = "^ +\\s*";
} else if (type == 0) {
pattern = "\\s";
//temp.replace(" ", "");
} else if (type == 1) {
pattern = "\\s* +$";
} else if (type == 2) {
temp = temp.trimmed();
} else if (type == 3) {
temp = temp.simplified();
}
//è°ç¨æ£å表达å¼ç§»é¤ç©ºæ ¼
if (!pattern.isEmpty()) {
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
temp.remove(QRegularExpression(pattern));
#else
temp.remove(QRegExp(pattern));
#endif
}
return temp;
}
//æµè¯ä»£ç
QString text = " a b c d ";
//ç»æï¼a b c d
QtHelper::trimmed(text, -1);
//ç»æï¼abcd
QtHelper::trimmed(text, 0);
//ç»æï¼ a b c d
QtHelper::trimmed(text, 1);
//ç»æï¼a b c d
QtHelper::trimmed(text, 2);
//ç»æï¼a b c d
QtHelper::trimmed(text, 3);
- Qtçç½ç»åºæ¯æudp广ææç´¢åç»ææç´¢ï¼å ¶ä¸ç»ææç´¢å¯ä»¥è·¨ç½æ®µæç´¢ï¼ææ¶åä½ ä¼åç°å¤±çµï¼æ¤æ¶ä½ å¯ä»¥å°è¯ææ¬å°çèææºçç½å¡ç¦ç¨è¯è¯ï¼ä¼°è®¡å°±å¥½äºãè¿æå°±æ¯å¨æ¬å°å¼å¯äºä»£çå¥çï¼å å ³æè¯è¯ãè¿æå¨ä½¿ç¨tcpsocketè¿æ¥çæ¶åï¼åç°å¨Qt4åQt5ä¸æ£å¸¸çç¨åºï¼å°äºQt6ä¸å°±ä¸è¡äºï¼æ¥éæ示 The proxy type is invalid for this operation ï¼åæ¥æ¯æ¬å°è®¾ç½®äºä»£ç导è´çï¼å¯è½å¨Qt6以åä¼é»è®¤è·³è¿å»ä¸å¤çã
//ä¹å¯ä»¥éè¿ä»£ç 设置跳è¿ä»£ç
#include <QNetworkProxy>
QNetworkProxyFactory::setUseSystemConfiguration(false);
//ä¸é¢è¿æ ·æ¯æ¬¡è®¾ç½®ä¹å¯ä»¥
tcpSocket->setProxy(QNetworkProxy::NoProxy);
//æ¥é
å°æç« https://www.cnblogs.com/cppskill/p/11730452.html
//ä»5.8å¼å§socketé»è®¤ä»£çç±»åæ¯DefaultProxyèä¸æ¯NoProxyï¼ä¸ç¥éåºäºä»ä¹èèã
- å ³äºäº¤åç¼è¯ï¼å¯¹äºåå¦è æ¥è¯´æ¯ä¸ªæé¾è·¨è¿å»çç ï¼ä¸æ¦è·¨è¿å»äºï¼ä»¥åéå°éè¦äº¤åç¼è¯çæ¶åé½æ¯é¡ºæ°´æ¨èãä¿¡æææ¥ãï¼ï¼å 为éè¦æ建交åç¼è¯ç¯å¢ï¼å¥½å¨ç°å¨å家æä¾çæ¿ååºæ¬ä¸é½æ¯æµè¯å¥½çç¯å¢ï¼å°¤å ¶æ¯æä¾çç¼è¯å¨ï¼ä¸ç¨èªå·±åå»æè ¾ï¼æç §å®æ¹æåæ¥åºæ¬ä¸ä¸ä¼æå¥ççé®é¢ã
- å¨linuxç³»ç»ä¸ç¼è¯ffmpegåqté½æ¯é常ç®åçäºæ ï¼åå¦è ä¹ä¼ï¼åæåªè¦æ¬å°çgcc g++ç¼è¯å¨æ£å¸¸ã
- ä»»ä½ç¼è¯å¨å æ¬åµå ¥å¼ç¼è¯å¨ï¼ä¸ºäºç¡®ä¿ç¯å¢æ£å¸¸ï¼ä½ å¯ä»¥å æ¥ç对åºçç¼è¯å¨çæ¬æ¯å¦okï¼g++ -v arm-linux-g++ -vã
- 交åç¼è¯å¨æ¥ççæ¬ /opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-g++ -v ã
- ç¼è¯å¨ä½æ°åæä½ç³»ç»ä½æ°æå ³ï¼ä¸è¬32ä½çç¼è¯å¨è¦å¨32ä½çç³»ç»ä¸å交åç¼è¯ï¼è½ç¶32ä½ä¹å¯ä»¥å¨å®è£ ä¾èµåï¼å¨64ä½ç³»ç»å交åç¼è¯ï¼ä½æ¯ä¸ªäººä¸å»ºè®®ï¼å¯è½ä¼åºé®é¢ã64ä½çç¼è¯å¨åªè½å¨64ä½çç³»ç»ã
- 设置äºç¯å¢åéåå¯ä»¥çç¥æé¿é¿çè·¯å¾ï¼ç´æ¥æå¯æ§è¡æ件å称å³å¯ï¼æ²¡æ设置ç¯å¢åéåéè¦æå®æ´è·¯å¾ã
- 设置ç¯å¢åéåªæ¯ä¸ºäºç¼è¯çæ¶å让èªå¨å¯»æ¾ç¼è¯å¨ï¼å ¶å®ä¹å®å ¨å¯ä»¥ä¸ç¨è®¾ç½®ç¯å¢åéï¼ä½¿ç¨ç»å¯¹è·¯å¾æå®ç¼è¯å¨ä½ç½®å³å¯ã
- å¨linuxä¸ç¼è¯ï¼æ 论æ¯ffmpegè¿æ¯qtè¿æ¯å ¶ä»ï¼é½æ¯éç¨çæ¥éª¤ï¼ç¬¬ä¸æ¥ï¼./configure 第äºæ¥ï¼make 第ä¸æ¥ï¼make install ã
- è³äºå ·ä½configureåé¢æåªäºåæ°ï¼åç §å¯¹åºæºç å çæåå°±è¡ï¼æç´¢ä¹ä¸å¤§å ãå½ç¶ä½ ç¨é»è®¤çå°±ä¸å¸¦ä»»ä½åæ°ä¸è¬ä¹å¯ä»¥ï¼èªå¨éç¨é»è®¤åæ°è¿è¡ç¼è¯ã
- 交åç¼è¯ffmpegå½ä»¤ï¼./configure --prefix=host --enable-static --disable-shared --disable-doc --cross-prefix=/opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux- --arch=arm --target-os=linux
- 交åç¼è¯qtåæï¼ä¿®æ¹mkspecs/qws/linux-arm-g++ä¸é¢çqmake.confï¼å¦æ没æ设置ç¯å¢åéå设置对åºç¼è¯å¨çç»å¯¹è·¯å¾ï¼å¹¶å°ç¼è¯å¨çååæ¹æä½ éè¦çã
- æ¯å¦ä¿®æ¹gccç¼è¯å¨ï¼QMAKE_CC = /opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-gcc
- 交åç¼è¯qt4.8.5å½ä»¤ï¼./configure -prefix host -embedded arm -xplatform qws/linux-arm-g++ -release -opensource -confirm-license -qt-sql-sqlite -qt-gfx-linuxfb -plugin-sql-sqlit -no-qt3support -no-phonon -no-svg -no-webkit -no-javascript-jit -no-script -no-scripttools -no-declarative -no-declarative-debug -qt-zlib -no-gif -qt-libtiff -qt-libpng -no-libmng -qt-libjpeg -no-rpath -no-pch -no-3dnow -no-avx -no-neon -no-openssl -no-nis -no-cups -no-dbus -little-endian -qt-freetype -no-opengl -no-glib -nomake demos -nomake examples -nomake docs -nomake tools
- 交åç¼è¯qt5.9.8å½ä»¤ï¼./configure -prefix host -xplatform linux-arm-g++ -recheck-all -opensource -confirm-license -optimized-qmake -release -no-separate-debug-info -strip -shared -static -c++std c++1z -no-sse2 -pch -compile-examples -gui -widgets -no-dbus -no-openssl -no-cups -no-opengl -linuxfb -qt-zlib -qt-libpng -qt-libjpeg -qt-freetype
- 综ä¸æ述交åç¼è¯å常è§çç¼è¯å°±ä¸ä¸ªåºå«ï¼éè¦æå¨æå®äº¤åç¼è¯å¨è·¯å¾ãffmpegæ¯éè¿--cross-prefix=æå®ï¼qtæ¯è¾åºå¤§æ¯éè¿æ´æ¹é ç½®æ件æåéè¿-xplatformæå®é ç½®æ件å称ã
- Qt6çç¼è¯æ¯è¾ç¹çï¼é»è®¤ç¨cmakeç¼è¯ï¼å¨linuxä¸å ç¨cmake3.19以ä¸çæ¬çæºç ï¼ç¨makeç¼è¯çæcmakeï¼ç¶ååç¨cmakeç¼è¯qtçæqmakeï¼æåè°ç¨qmakeæ¥ç¼è¯ä½ çqt项ç®ã
- ç¼è¯Qtå ¶å®åªæ¯æ³ç¨å ¶ä¸çåºï¼è³äºdemoãdocãtoolãexampleçç»ç»ä¸ç¨ï¼è´¹æ¶è´¹åãæ以强ç建议ç¼è¯çæ¶åå»æï¼æ大å å¿«ç¼è¯é度ã
- ç¼è¯å»ºè®®ç¨æ®éç¨æ·ç¼è¯å³å¯ï¼å æ¬è§£åæºç ï¼å 为è¿æ ·ç¼è¯åºæ¥çåºæ®éç¨æ·å°±è½ç¨ï¼å¦ææ¯root管çåç¼è¯çå以åé½éè¦ç®¡çåæéæè¡ã
- å¾å¤ç³»ç»é½æä¾äºç´æ¥é¼ æ å³é®è§£åï¼å ¶å®ä¹æ¯å¯ä»¥çï¼å°±æ¯éåº¦æ ¢ï¼å»ºè®®ç¨å½ä»¤è¡è§£ååå é¤ç®å½ã
- Qtçç¼è¯åæ°æ¯ä¸ªçæ¬é½å¯è½æåºå ¥ï¼æ¯ç«ä¸ç´å¨æ´æ°ä»£ç ï¼çè³æäºåç±»æè¿°åäºï¼æ¯å¦ä¹å-qt-xcbå°äº5.15æ¹æäº-xcbï¼ä¹å-qt-sql-sqliteæ¹æäº-qt-sqliteï¼ä¸å®è¦çæºç ä¸çreadmeï¼éé¢çº¦å®äºç¼è¯ç¯å¢è¦æ±çæä½çæ¬ï¼åé¢qt5å¼å§å ·ä½çé ç½®åæ°æåªäºæ¾å°äºqtbaseç®å½ä¸çconfig说æã
- ç¼è¯å®æ使ç¨å¦æéå°æ示 GL/gl.h é误ï¼éè¦å®è£ apt install libgl1-mesa-dev libglu1-mesa-dev æè yum install mesa-libGL-devel mesa-libGLU-devel ã
- ç¼è¯åæ°è¯´æå¯åè https://blog.csdn.net/xi_gua_gua/article/details/53413930ã
- å¨Qtä¸è®¾ç½®å¾çææ¶åä¼åç°ä¸æåï¼å¾å¯è½æ¯å 为æ件çæå±åä¸æ£ç¡®å¯¼è´çï¼æ¯å¦jpgçå¾çæå±åæ¯pngï¼bmpçå¾çæå±åæ¹æäºjpgï¼QImageãQPixmapä¼ å ¥æ件路å¾å è½½å¾çï¼æ¯éè¿æå±åå»è°ç¨å¯¹åºçå¾ç解æç®æ³ï¼æ¯è¾å»ï¼ä½æ¯é度快ï¼ä¸ç¨ç»è¿åæå ·ä½å é¨æ¯ä½ç§å¾çæ ¼å¼ãå¦ææ³è¦ä¸ç®¡æå±åé½è½ä¿è¯å è½½æåï¼åå¿ é¡»è¯»åå¾çæ件æ°æ®å è½½çæ¹å¼å¤çã
//å¯ä»¥æ¯èµæºæ件ä¸çå¾çä¹å¯ä»¥æ¯æ¬å°æ件
QString fileName = ":/test.png";
//æ¤æ¹å¼æç
§æå±åæ¥åºåå
·ä½æ ¼å¼ä¸åç¡®
//å¦ææå±åä¸æ£ç¡®å°±æ æ³å è½½æå
ui->label->setPixmap(QPixmap(fileName));
//éè¿ç´æ¥è¯»åå¾çæ°æ®å è½½ä¿è¯æå
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QByteArray data = file.readAll();
//éè¿ QImage å¤ç
QImage img;
img.loadFromData(data);
//ä¸é¢è¿ç§æ¹å¼ä¹è¡
//QImage img = QImage::fromData(data);
ui->label->setPixmap(QPixmap::fromImage(img));
//éè¿ QPixmap å¤ç
QPixmap pix;
pix.loadFromData(data);
ui->label->setPixmap(pix);
- æ»ç»å 个Qtçæ¬çå·ç¥è¯ã
- Qt4.8.7æ¯Qt4çç»ç»çæ¬ï¼æ¯Qt4ç³»åçæ¬ä¸æ稳å®æç»å ¸çï¼å¾å¤åµå ¥å¼æ¿åè¿æ¯ç¨Qt4.8ï¼ï¼å ¶å®è¯¥çæ¬æ¯åQt5.5å·®ä¸å¤æ¶é´åå¸çãåèé¾æ¥ https://www.qt.io/blog/2015/05/26/qt-4-8-7-released https://blog.qt.io/blog/2015/07/01/qt-5-5-released/
- Qt5.6.3ææåæ¯æxpç³»ç»çé¿ææ¯æçæ¬ï¼Qt5.7.0æ¯æåæ¯æxpç³»ç»çéé¿ææ¯æçæ¬ï¼æå¯è½ææå°æ°å½æ°ä¸æ¯æï¼ä¸ªäººæ²¡éå°è¿ï¼ã
- Qt5.12.3æ¯æåæä¾mysqlæ°æ®åºæ件ççæ¬ï¼å¾åççæ¬éè¦èªè¡ç¼è¯å¯¹åºçmysqlæ°æ®åºæ件ï¼å®æ¹å®è£ å ä¸åæä¾ã
- Qt5.12.5æ¯æåæ ·å¼è¡¨æ§è½æé«ççæ¬ï¼ç»è¿é ·ç 大佬æ¥é 代ç åç°æ¤åçæ¬çæ ·å¼è¡¨æºç ä¸ä¸ºäºä¿®å¤ä¸ä¸ªbugåäºå¾ªç¯åµå¥è®¾ç½®ï¼å¯¼è´æ§è½æ¥å§ä¸éï¼çé¢è¶å¤æ§è½æ´é10å以ä¸ã
- Qt5.14.2æ¯æåæä¾äºè¿å¶å®è£ å ççæ¬ï¼åé¢ççæ¬é½éè¦å¨çº¿å®è£ ã
- Qt5.15ç³»åæ¯æåæ¯æwin7ççæ¬ï¼åé¢çQt6ç³»åçæ¬éè¦æ´æ¹æºç ç¼è¯æè½æ¯æwin7ï¼è¿å¯¹äºå°ç½æ¥è¯´é¾äºä¸é天ã
- Qt6.0/6.1çæ¬å ¶å®ä¹æ¯æ¯æwin7çï¼ä½æ¯å 为缺失太å¤æ¨¡åï¼èä¸BUGæå±±ï¼å¤§ä½¬è¯´äºçé½ä¸ç¨ï¼æ以使ç¨æ¤çæ¬æ²¡æä¹ã
- Qt6ä¸æ¯æwin7ï¼æ¯è¯´å¼åé¶æ®µåè¿è¡é¶æ®µé½ä¸æ¯æï¼æ 论å¼åé¶æ®µè¿æ¯è¿è¡é¶æ®µä½ é½éè¦Qtçåºï¼åªè¦æ¯Qtçåºä¸æ¯æï¼å°åªéä¹ä¸æ¯æã
- æ°ççqtc7ç±äºéç¨Qt6ç¼è¯ï¼æ以ä¹åªè½å¨win10å以ä¸è¿è¡ï¼æå³çä½ è¦ç¨æ°çqtc7+Qt5åå¼åä¹å¿ é¡»ç¨win10å以ä¸ã
- 欢è¿åä½è¡¥å ï¼æ¯å¦åªä¸ªçæ¬ä»¥ååç¨éè¦æ¶è´¹ä¹ç±»çï¼è²ä¼¼ç¨Qt4ï¼å¨ä¸æ´æ¹Qtæ¬èº«æºç ï¼å¨æåºåå¸ç¨åºï¼æ³å¾é£é©å°ä¸äºï¼
- Qtå®æ¹é¤äºQtåºä¸ç´å¨å级å¤ï¼å¯¹åºçéæå¼åç¯å¢ä¹å¨æ´æ°å级ï¼ä¸è¬ä¼éç¨ææ°çQtåºç¼è¯æ°çæ¬ï¼è¦æ³¨æçæ¯ï¼æäºäººå®è£ çæ§çæ¬çqtcï¼å è½½æ¯è¾é«çæ¬çQtåºï¼å¾å®¹æåºç°æ¥éæ示 Project ERROR: Cannot run compiler 'g++'. Maybe you forgot to setup the environment? ä¹ç±»çï¼ä¸è¬æ¯çæ¬è·¨åº¦è¿å¤§ï¼æ¯å¦ç¨Qt5.5é带çqtcå è½½Qt5.9çåºï¼å¯¼è´æäºç¯å¢è¯å«ä¸å°ï¼å¯è½æ¯qtcå¨æ°çæ¬ä¸å¯¹æäºè¯å«å¤çè§åæåå¨ãæ以ä¸è¬å»ºè®®å¯ä»¥ç¨æ°çqtcå è½½æ§çQtåºï¼ä¸å»ºè®®æ§çqtcå è½½æ°çQtåºã
23ï¼221-230
- å¨å¯¹è¡¨æ ¼æ°æ®æ¨¡åæä½çæ¶åï¼ç»å¸¸éå°ä¸ç§åºæ¯å°±æ¯ï¼å é¤ææ¡è®°å½åï¼å¸æéæ°éä¸æä¸è¡ãQTableViewãQTableWidgetæ¬èº«å°±æ¯æå¤éå ¨éçæä½ï¼æ¯å¦æ¹éå é¤å¯ä»¥å¤éã
//æ¿å°è¡¨æ ¼æ°æ®æ¨¡å
QAbstractItemModel *model = ui->tableView->model();
//主å¨å®ä½å°ç¬¬ä¸è¡
ui->tableView->setCurrentIndex(model->index(3, 0));
//主å¨å®ä½å°æåä¸è¡
ui->tableView->setCurrentIndex(model->index(model->rowCount() - 1, 0));
//设置éæ©æ¨¡å¼æ¯æå¤éï¼å
¶ä»å 个æ举å¼èªè¡æ¥é
ææ¡£ã
ui->tableView->setSelectionMode(QAbstractItemView::MultiSelection);
//éæ©å
¨é¨
ui->tableView->selectAll();
//åæ¶ææéä¸
ui->tableView->clearSelection();
//éä¸è¡ï¼æ³¨æå¦æ该è¡éä¸åæ§è¡ååæ¶éä¸ï¼å¦æ¤å¾å¤ãè¿ä¸ªè®¾è®¡å¾å·§å¦ï¼æ声ã
ui->tableView->selectRow(row);
//éä¸åï¼æ³¨æå¦æ该åéä¸åæ§è¡ååæ¶éä¸ï¼å¦æ¤å¾å¤ãè¿ä¸ªè®¾è®¡å¾å·§å¦ï¼æ声ã
ui->tableView->selectColumn(column);
//è·åéä¸è¡çå
容
QItemSelectionModel *selections = ui->tableView->selectionModel();
QModelIndexList selected = selections->selectedIndexes();
foreach (QModelIndex index, selected) {
qDebug() << index.row() << index.column() << index.data();
}
- å¨è¯»åææ¬æ件çæ¶åï¼ææ¶åä¼åç°è¯»ååºæ¥çä¸æä¹±ç ï¼è¿ä¸ªæ¶åå°±éè¦è¯å«æ件ç¼ç æ ¼å¼ï¼ç¶å主å¨è®¾ç½®å¯¹åºçç¼ç å»è¯»åå°±ä¸ä¼ä¹±ç ã
//æ£æ¥æ件ç¼ç 0=ANSI 1=UTF-16LE 2=UTF-16BE 3=UTF-8 4=UTF-8BOM
int DataCsv::findCode(const QString &fileName)
{
//åå®é»è®¤ç¼ç utf8
int code = 3;
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
//读å3åèç¨äºå¤æ
QByteArray buffer = file.read(3);
quint8 b1 = buffer.at(0);
quint8 b2 = buffer.at(1);
quint8 b3 = buffer.at(2);
if (b1 == 0xFF && b2 == 0xFE) {
code = 1;
} else if (b1 == 0xFE && b2 == 0xFF) {
code = 2;
} else if (b1 == 0xEF && b2 == 0xBB && b3 == 0xBF) {
code = 4;
} else {
//å°è¯ç¨utf8转æ¢,å¦æå¯ç¨å符æ°å¤§äº0,å表示æ¯ansiç¼ç
QTextCodec::ConverterState state;
QTextCodec *codec = QTextCodec::codecForName("utf-8");
codec->toUnicode(buffer.constData(), buffer.size(), &state);
if (state.invalidChars > 0) {
code = 0;
}
}
file.close();
}
return code;
}
-
å¨è¿æ¥è¿ç¨æ°æ®åºè¿è¡æ¥è¯¢æ°æ®çæ¶åï¼ææ¶åä¼åç°å¾æ ¢ï¼å°¤å ¶æ¯è¡¨æ°æ®éè¶å¤è¶æ ¢ï¼æ¬å°çè¯åçæ°æ®éå¿«å¾å¤ï¼å¯ä»¥å°è¯å¼å¯åªåè¿å±æ§ï¼query.setForwardOnly(true);è¿æ ·çè¯åªä¼ç¼åä¸æ¬¡çæ°æ®ï¼æ大æé«è¿ç¨æ°æ®åºçæ¥è¯¢æçï¼æ®è¯´å¯ä»¥æé«å ååç¾åçé度ãå½ç¶åææ¯å¯¹æ¥è¯¢çæ°æ®ä¹ååååæ°æ®çéæ±ï¼å¦æè¿è¦å¾ååæ°æ®æè å¨æ°æ®æ¨¡åQSqlQueryModelä¸ä½¿ç¨ï¼åä¸è½å¼å¯æ¤å±æ§ãåå å¨æ¯æ¬¡å©ç¨QSqlQueryè·åä¸ä¸æ¡è®°å½æ¶ï¼è¥ä¸å¼å¯isForwardOnlyå±æ§ï¼å¾éæ¾é»è®¤å°±æ¯ä¸å¼å¯ï¼ï¼åæ¯æ¬¡é½å¼è¾æ°çå å空é´ï¼æ¥åå¨å·²ç»è®¿é®åæªè®¿é®çè®°å½ï¼è¿æ ·ï¼æ¯æ¬¡é½ä¼æµªè´¹å¥½å¤åå¨ç©ºé´ã
-
Qtä¸çpainterç»å¶é常çµæ´»å¼ºå¤§ï¼æ¥å£ä¸°å¯ï¼ä½æ¯å¯¹äºå¾å¤åå¦è æ¥è¯´è¿æ¯æä¸å®çé¾åº¦ï¼å°¤å ¶æ¯åç§å¥å¥æªæªçå¤ææ ¼å¼ï¼èè¿äºæ ¼å¼ç¨htmlç¡®å¾å¥½æè¿°ï¼æ¯å¦æ§å¶è¡é´è·ãå符é´è·çï¼æ¤æ¶å¯ä»¥ç¨QTextDocumentä¼ å ¥htmlæ ¼å¼å 容交ç»QPainterç»å¶ï¼é常å®ç¾ãç®åã强大ï¼å æ¬ä¸äºæ°å¦å ¬å¼å¥çã
void Form::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QTextDocument doc;
doc.setHtml(html);
//设置ææ¬å®½åº¦
doc.setTextWidth(200);
//æå®ç»å¶åºå
doc.drawContents(&painter, QRect(0, 0, 200, 70));
}
- Qtä¸æ ·å¼è¡¨å¯¹éä¸é¢è²åæ¬åé¢è²æ¯æä¼å 级çï¼æ ¹æ®å¯¹æä½ç³»ç»é»è®¤æ ·å¼çè§å¯ï¼å½å¤äºéä¸ç¶æ+æ¬åç¶æçæ¶åï¼é»è®¤åæ¬åç¶æï¼ä¹å°±æ¯é¼ æ 移å¨å°éä¸çå表itemä¸ï¼é¢è²åæ¬åç¶æé¢è²ãèQtä¸å¦æ两ç§é¢è²é½è®¾ç½®äºï¼æ ¹æ®è®¾ç½®ç顺åºæ¥ï¼åæåç为åï¼å¦ææå设置çéä¸ç¶æé¢è²ï¼åå½itemå¤äºéä¸ç¶æ+æ¬åç¶æçæ¶åï¼åéä¸ç¶æé¢è²èä¸æ¯æ¬åç¶æé¢è²ï¼åè®°ï¼
//ä¸é¢è¿æ ·è®¾ç½®åå½é¼ æ åçå¨éä¸çitemä¸æ¶èæ¯é¢è²=#00FF00
QTableView::item:selected{background:#FF0000;}
QTableView::item:hover{background:#00FF00;}
//ä¸é¢è¿æ ·è®¾ç½®åå½é¼ æ åçå¨éä¸çitemä¸æ¶èæ¯é¢è²=#FF0000
QTableView::item:hover{background:#00FF00;}
QTableView::item:selected{background:#FF0000;}
//å·¦ä¸è§æ ·å¼å¾å®¹æ忽ç¥
QTableCornerButton:section{background:#FF0000;}
- qtcå¼åå·¥å ·å ç½®äºä¸å°çå½æ°ï¼å¯ä»¥å¾æ¹ä¾¿çè¿è¡ä¸äºå¤æåå¤çã
//æå°çæ¬è¦æ±
!minQtVersion(5, 15, 2) {
message("Cannot build Qt Installer Framework with Qt version $${QT_VERSION}.")
error("Use at least Qt 5.15.2.")
}
- ææ¶åææ¬æ¡ä¸çå 容è¿é¿ï¼èææ¬æ¡é»è®¤å æ å¨å°¾é¨ï¼æ以è¦ä¸»å¨è®¾ç½®ä¸å°å æ 移å°æåé¢
//ä¸ç§æ¹æ³é½å¯ä»¥
ui->lineEdit->setSelection(0, 0);
ui->lineEdit->setCursorPosition(0);
//æ ·å¼è¡¨æ¹å¼
"QLineEdit{qproperty-cursorPosition:0;}
- å ³äºQtæµè§å¨æ¨¡åçå ç¹è¯´æã
- Qt5.6以åç¨çæ¯webkitï¼Qt5.6çæ¬ä»¥åå两ç§æ åµï¼ä¸ç§æ¯mingwç¼è¯å¨ï¼windowsç³»ç»ï¼å¯¹åºçQtåºä¸åæä¾æµè§å¨æ¨¡åã
- Qt5.6以åççæ¬å¨linuxç³»ç»åmacçç³»ç»ï¼é½ä¸åå¨æ²¡ææµè§å¨æ§ä»¶çæ åµï¼é½ä½¿ç¨çæ¯webengineã
- ä» ä» æ¯windowsä¸çmingwç¼è¯å¨çQtçæ¬æ²¡æï¼å ¶ä»ç³»ç»å ¶å®é½æçãå¾å¤äººå¨è¿ä¸ªå°æ¹é½æçé®ï¼é½ä»¥ä¸ºåªæmsvcç¼è¯å¨ææµè§å¨æ§ä»¶ï¼å ¶å®ç¡®åç说æ¯å¨windowsä¸msvcçQtåºå¸¦æµè§å¨æ§ä»¶ã
- å®è£ Qtçæ¶åwebengine模åé»è®¤ä¸å¾éï¼éè¦ä¸»å¨å¾éæä¼å®è£ ã
- ä¹ä¸æ¯ææçmsvcçQtçæ¬é½æwebengineæµè§å¨æ¨¡åï¼åªæä½ å¾éäºä¹æ²¡ç¨ï¼æäºçæ¬å®æ¹å¹¶æ²¡æç¼è¯ï¼éè¦èªè¡ç¼è¯ãéè¦å°å¯¹åºçQtå®è£ ç®å½æ¥çæ¯å¦æ Qt5WebEngine.dll æ件ã
- å¦æä» ä» æ¯ä¸ºäºå¼¥è¡¥mingwçæ¬ç¼ºå¤±æµè§å¨æ¨¡åçéæ¾ï¼æ¨èç¨miniblinkã
- å¦æ为äºç»ä¸å ¼å®¹åç§çæ¬åç³»ç»ï¼æ¨èç¨cefã
- å¦æ没æåå²å 袱ï¼æ¨èç¨webengineï¼ä¸Qtçéæ度é«ã
- webkitåminiblinké»è®¤é½ä¸æ¯ægpuï¼webengineé»è®¤èµ°gpuã
- qwebengineé»è®¤ä¸æ¯æMP4ï¼éè¦èªå·±éæ°ç¼è¯ã
- å ³äºç¼è¯æ°æ®åºæ件çå 个ç»éªæ»ç»ã
- å®è£ 对åºçæ°æ®åºï¼å®è£ åä¼æinclude头æ件ålibé¾æ¥åºæ件ï¼è¿æ¯åºæ¬çåæï¼ç¼è¯æ°æ®åºæä»¶å¿ é¡»è¦æè¿ä¸¤ä¸ªä¸è¥¿ãå¡å¿ 注æï¼32ä½çQtå¿ é¡»å®è£ 32ä½çæ°æ®åºæè½æ£å¸¸ç¼è¯æåï¼ä½æ°è¦ä¸è´ã
- åå¤å¥½æ°æ®åºæ件æºç ï¼æ¯å¦qt-everywhere-src-5.14.2\qtbase\src\plugins\sqldrivers\mysqlï¼å¯ä»¥å¨å®è£ Qtçæ¶åå¾ésrcï¼æè åæç´æ¥å®ç½éæ°ä¸è½½æºç 解ååºæ¥ã
- æå¼ä½ è¦ç¼è¯çæ°æ®åºæ件æºç ï¼æ¯å¦mysqlå°±æå¼mysql.proï¼oracleå°±æå¼oci.proã
- å¨proä¸æ³¨éæä¸è¡ #QMAKE_USE += mysqlï¼å¦ææ¯oci项ç®åæ¯#QMAKE_USE += ociã
- qsqldriverbase.priæ件ä¸æ³¨éæ #include(..shadowed(..PWD)/qtsqldrivers-config.pri)ã
- mysql.proæ件å 容ä¸é¢å ä¸å¦ä¸ä»£ç ã
path = C:/Qt/mysql-5.7.30-winx64
INCLUDEPATH += $$path/include
win32:LIBS += -L$$path/lib -llibmysql
- oci.proæ件å 容ä¸é¢å ä¸å¦ä¸ä»£ç ã
path = C:/app/Administrator/product/11.2.0/client_1
INCLUDEPATH += $$path/oci/include
win32:LIBS += -L$$path/oci/lib/msvc -loci
- psql.proæ件å 容ä¸é¢å ä¸å¦ä¸ä»£ç ã
path = "C:/Program Files/PostgreSQL/13"
INCLUDEPATH += $$path/include
win32:LIBS += -L$$path/lib -llibpq
- 以ä¸åæ³åæ¶æ¯æmingwåmsvcï¼å ¶ä»ç³»ç»ç¼è¯è¿ç¨ä¹æ¯ç±»ä¼¼ãç¼è¯å®æåé»è®¤ä¼å¨ä½ å½åæºç æå¨ç符çæ ¹ç®å½ä¸ï¼ä¼åºç°pluginsç®å½ï¼éé¢sqldriversç®å½ä¸å°±æ¯å¯¹åºç¼è¯çæ好çæ件å¨æåºã
- é»è®¤oracleçæ件驱å¨ä»£ç æ¯æç §oracle12çå½æ°åçï¼å¦æé¾æ¥çæ¯oracle11ï¼åéè¦æ¹å¨ä¸¤è¡ä»£ç æè½ç¼è¯æåãæå¼qsql_oci.cppæ件大æ¦å¨1559è¡ä»£ç å·¦å³ï¼æ个OCIBindByPos2å½æ°æ¹æOCIBindByPosï¼ä¸é¢è¿æä¸è¡bindColumn.lengthsæ¹æ(ub2*)bindColumn.lengthsã
- å ³äºQtæ°æ®åºå¼åçä¸äºå·ç¥è¯ã
- Qtå³æ¯æåºçå½¢å¼ç´æ¥åæ°æ®åºéä¿¡ï¼ä¹æ¯æODBCæ°æ®æºçå½¢å¼ååç§æ°æ®åºéä¿¡ï¼è¿æ ·å°±æ¶µçäºææçæ åµã
- Qtæ°æ®åºç¨åºæå åå¸ï¼ææåæï¼æ³¨æåºå32/64ä½ï¼ä½ çç¨åºæ¯32ä½çå°±å¿ é¡»å¸¦ä¸32ä½çåºï¼64ä½çå¿ é¡»å¸¦ä¸64ä½çåºï¼è¿ç¹Qtçåºä¹æ¯è¿ä¸ªè¦æ±ãmysqlåå¸æç®åï¼å¸¦ä¸ä¸ä¸ªmysqlçå¨æåºæ件就è¡ï¼windowsä¸çæ¯libmysql.dllï¼ï¼é常ç®åãsqlserverä¸ç¨å¸¦ï¼å 为æ¯å¾®è½¯ç亲å¿åï¼ä¸è¬æä½ç³»ç»èªå¸¦ãpostgreséè¦å¸¦ä¸libpq.dllãlibintl-8.dllãlibiconv-2.dllãlibeay32.dllãssleay32.dllè¿å 个æ件就è¡ãoracleéè¦å¸¦ä¸oci.dllãoraociei11.dllï¼è¿ä¸ªæ件å¾å¤§æ130MB+ï¼ï¼å¦æä¸è¡å»ºè®®ç´æ¥å®è£ 个oracle client客æ·ç«¯è½¯ä»¶ï¼ç¶å对åºbinç®å½è®¾ç½®å°ç¯å¢åé就好ã
- æå åå¸åæµè¯ä¸æ¥ï¼åç°32ä½çç¨åºä¹å¯ä»¥æ£å¸¸è¿æ¥64ä½çmysqlï¼64ä½çç¨åºä¹å¯ä»¥æ£å¸¸è¿æ¥32ä½çmysqlï¼å æ¤å¤æåªè¦åç¨åºçåºçä½æ°ä¸è´å°±è¡ï¼ç¼è¯çæ¶åä¹æ¯è¿ä¸ªè§åï¼32ä½çQtç¨åºç¼è¯æ°æ®åºæ件ä¹è¦ç¨32ä½çæ°æ®åºé¾æ¥åºãï¼ï¼ä¸éè¦åå ·ä½çæ°æ®åºçä½æ°ä¸è´ï¼æµè¯è¿mysqlãsqlserverãpostgresqlæ°æ®åºé½æ¯ç±»ä¼¼è§åã
- 大éæµè¯å¯¹æ¯ä¸æ¥ï¼éè¿odbcæ°æ®æºçæ¹å¼åç´è¿æ°æ®åºçæ¹å¼æ¹éæå ¥å¤§éæ°æ®è®°å½ï¼ç´è¿æ¹å¼é度æ´å¿«ï¼çº¦5%å·¦å³ï¼æ以建议尽ééç¨æ¤æ¹å¼ï¼æ¯å¨æ²¡ææ¤æ¹å¼çç¯å¢æéç¨odbcæ°æ®æºçæ¹å¼ï¼Qté»è®¤èªå¸¦odbcæ°æ®åºæ件ã
- ä¸åæ°æ®åºå¨æ§è¡sqlèæ¬çæ¶åï¼ä¼èªå¨å°è¡¨åæè å段å转æ大åæå°åï¼mysqlä¼å°è¡¨å转æå°åãpostgresqlä¼å°è¡¨ååå段å转æå°åãoracleä¼å°è¡¨ååå段å转æ大åãè¿å°±å¯¼è´ä½¿ç¨QSqlTableModelè°ç¨setTable设置æ°æ®åºè¡¨åçæ¶åï¼ä¸å®è¦åæ°æ®åºä¸ç表åä¸è´ï¼åºå大å°åï¼æ以就æ¯å¨å¯¹postgresqlåoracleæ°æ®åºçæ¶åä¸å®è¦æ³¨æï¼æ¬äººå°±æ¯å¨è¿éå¡äºå¾ä¹ ï¼å·®ç¹è¦æè¿å·¨å¤§çå±çæ£å¨QtçBUGä¸ã
void DbHelper::bindTable(const QString &dbType, QSqlTableModel *model, const QString &table)
{
//postgresqlå
¨é¨å°å,oracleå
¨é¨å¤§å,è¿ä¸¤ä¸ªæ°æ®åºä¸¥æ ¼åºå表åå段åç大å°åå§æ§½
QString flag = dbType.toUpper();
if (flag == "POSTGRESQL") {
model->setTable(table.toLower());
} else if (flag == "ORACLE") {
model->setTable(table.toUpper());
} else {
model->setTable(table);
}
}
- Qtæ¯æä¸æå®æ°æ®åºåæå¼æ°æ®åºï¼å 为ææ¶åæ¯è¦å¨è¿æ¥æ°æ®åºæå¡å¨åï¼æ§è¡sqlè¯å¥å建æ°æ®åºãæ°æ®åºé½è¿æ²¡åå¨æä¹è¿æ¥å¢ï¼æµè¯åç°sqliteãmysqlãsqlserverãpostgresqlé½æ¯æè¿ä¸ªç¹æ§ãå¨å é¤åå建æ°æ®åºçåææ¯è¯¥æ°æ®åºæ²¡æè¢«å ¶ä»ç¨åºå ç¨ï¼æ¯å¦å ¶ä»ç¨åºå·²ç»æå¼äºè¯¥æ°æ®åºåä¼æ§è¡å¤±è´¥ãè¿éæå°±æ磨è¿å¾å¤æ¬¡ï¼ä¸ºä»ä¹æ§è¡å¤±è´¥å¢ï¼åé¢åç°ç¬¬ä¸æ¹æ°æ®åºå·¥å ·å·²ç»æå¼äºè¯¥æ°æ®åºï¼æå·¥å ·å ³æå°±okäºã
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
//database.setDatabaseName("dbtool");
database.setHostName("127.0.0.1");
database.setPort(3306);
database.setUserName("root");
database.setPassword("root");
if (database.open()) {
QSqlQuery query(database);
qDebug() << "å é¤æ°æ®åº" << query.exec("drop database dbtool");
qDebug() << "å建æ°æ®åº" << query.exec("create database dbtool");
if (query.exec("select * from userinfo")) {
while (query.next()) {
qDebug() << "æ¥è¯¢æ°æ®åº" << query.value(0);
}
}
} else {
qDebug() << "æå¼æ°æ®åº" << database.lastError().text();
}
- ç¨QSqlQueryModel+QTableViewæ¾ç¤ºæ°æ®ï¼intç±»åçæ°æ®ï¼å¦æè¶ è¿100ä¸ï¼ä¼åæç§å¦è®¡æ°æ¾ç¤ºï¼è¿å°±å¾æ¼ç«äºï¼è¯å®ä¸æ¯èªå·±æ³è¦çç»æãæ¾éç½ç»æç´¢ï¼ç»äºæ¾å°ä¸ä¸ªåæ ·é®é¢çå¥ä»¬ï¼éè¦å¯¹è¿ä¸åå 个空çå§æå°±è¡ãåé¢åç°ç©ºå§æä¹ä¸è¡ï¼è¶ è¿1000ä¸æ¡åå±æ ·äºï¼éè¦ç»æ大æ³éè½½æ°æ®æ¨¡åæ¾ç¤ºã
ui->tableView->setItemDelegateForColumn(0, new QItemDelegate);
//ä¸é¢æ¯ç»æ大æ³
QVariant SqlQueryModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
//è¶
è¿100ä¸çæ°å¼ä¼è¢«ç§å¦è®¡æ°æ¾ç¤ºéè¦è¿é转æå符串æ¾ç¤º
if (role == Qt::DisplayRole) {
int result = value.toInt();
if (result >= 1000000) {
value = QString::number(result);
}
}
return value
}
- mysqlæ°æ®åºæå¤ç§æ°æ®åºå¼æï¼å ¶ä¸MyIsamä¸æ¯ææ°æ®åºäºå¡ï¼é»è®¤ä¸è¬æ¯è¿ä¸ªå¼æï¼æ以å½ä½ 使ç¨Qtä¸çtransactionæ¹æ³åcommitæ交æ¶åï¼ä¼åç°ä¸æåï¼å ¶å®äºå®ä¸åæ¯æåçï¼å»æ°æ®åºéé¢æ¥ç对åºçç»æåæ¯æ£ç¡®çãæ两个åæ³ï¼ç¬¬ä¸å°±æ¯å°æ°æ®åºå¼ææ¹æInnoDBï¼ç¬¬äºå°±æ¯å¨æ交åå个é误å¤æ if (database.commit() || !database.lastError().isValid()) ï¼é误ä¸å¯ç¨ä¹è¯´ææ¯æåçã
- å¦æéç¨odbcæ°æ®æºéä¿¡ï¼ååªé设置æ°æ®åºå称setDatabaseNameã设置ç¨æ·å称setUserNameã设置ç¨æ·å¯ç setPasswordè¿ä¸ä¸ªåæ°å³å¯ï¼å 为æ°æ®æºé ç½®çæ¶å就已ç»è®¾ç½®å¥½å¯¹åºç主æºå°åå端å£ä»¥åå ³èçæ°æ®åºå称ï¼æ以å¨ç¨odbcæ°æ®æºéä¿¡çæ¶ååªéè¦å次éªè¯ç¨æ·ä¿¡æ¯å³å¯ãè¿éç¹å«è¦æ³¨æçæ¯setDatabaseName设置æ°æ®åºå称è¦å¡«åæ°æ®æºé ç½®çå称ã
- ç»è¿å¤§éç对æ¯æµè¯ï¼å æ¬æå ¥ãå é¤ãæ¹éãæ¥è¯¢ãå页çæä½ï¼åä¸é级æ°æ®ï¼å¨Qtæ°æ®åºé¨åååºé度è¿åï¼å好度æåä¾æ¬¡æ¯ sqlite > postgresql > oracle > mysql > odbc ãåä¸é级以ä¸æ¯ postgresql > oracle > mysql > sqlite > odbc ã亿级å«ä»¥ä¸æ¯ oracle > postgresql > å ¶ä»ã以ä¸æµè¯å建ç«å¨åå¦è æ°´å¹³åºç¡ä¸ï¼è³äºååºå表ãèåæ¥è¯¢ãç¼åãå åæ°æ®åºçåç§é«çº§ç¥è¯ç¹æ²¡ç¨ä¸ã
- mysql主è¦æ两个çæ¬ï¼mysql5.7åmysql8ï¼å®æ¹è¯´æ¯8æ¯5è¦å¿«å¾å¤ï¼ä¸ªäººæµè¯ä¸æ¥ï¼5.7æ¯8è¦å¿«å¾å¤ï¼æ 论æ¯æ¥è¯¢ï¼è¿æ¯æ¹éæå ¥æ°æ®ï¼ä¸ç¥é为ä½ï¼ç½ä¸æç´¢çä¹æ¯è¿ä¸ªç»æï¼https://www.coder4.com/archives/7596ï¼ï¼å¤§å®¶é½è¯´8æ ¢äºå¾å¤ã
- mysqlæ个åæ¯å«mariadbï¼æ¯mysqlæ´çº¯æ£ï¼æ®è¯´åæ¹é¢é½åæmysqlï¼https://blog.csdn.net/x275920/article/details/123847792ï¼ï¼ä¸ªäººå¯¹æ¯æµè¯ä¸æ¥ä¹æ¯ç¡®å®æ¹éæå ¥åæ¥è¯¢æ§è½è¦å¥½ä¸å°ï¼å¹¶ä¸å®å ¨å ¼å®¹mysqlï¼çè³åºæ件ç´æ¥éå½åä¹å¯ä»¥ç´æ¥ä½¿ç¨ï¼æ¯å¦å°libmariadb.dllæ¹ælibmysql.dllå¯ä»¥ç´æ¥ä½¿ç¨ï¼èä¸ä½ç§¯è¿å°äºå «åï¼è¿ä¸ªå¥½ï¼åå¸çæ¶ååå°äºå¥½å å ã
- å¦ææ¯Qt+mysqlç¨åºï¼åå¸çæ¶å带çåºçæ¬è¦åæ件对åºæ°æ®åºçæ¬ä¸è´ï¼å¦åå¯è½æ²¡ææ°æ®åºäºå¡ç¹æ§ï¼database.driver()->hasFeature(QSqlDriver::Transactions)为åã
- QSqlTableModelå°è£ çé常好ï¼å¹¶ä¸ä¼ä¸æ¬¡æ§å è½½æææ°æ®ï¼èæ¯éçæ»å¨æ¡çæå¨å è½½éè¦çæ°æ®ï¼æµè¯ä¸äº¿æ¡ç表ï¼é度é常快ï¼åå åæ¡ç表é度ä¸æ ·ã
- å¨è¿æ¥ç½ç»æ°æ®åºçæ¶åï¼å¦æä½ æ¬å°ç½ç»è®¾ç½®äºä»£çï¼æ¯å¦ä½¿ç¨äºä»£çä¸githubçç½ç«ï¼å°±ä¼åç°Qtçæ°æ®åºç¨åºè¿ä¸ä¸ï¼ä½ éè¦è®¾ç½®ä¸ä¸ä½¿ç¨æ¬å°ä»£ç设置 QNetworkProxyFactory::setUseSystemConfiguration(false) ãè¿ä¸ªå°æ¹å¦æä¸ä»ç»ä¼æ¾é®é¢æ¾å°ä½ æç人çã
24ï¼231-240
- å ³äºc++ä¸ç»§æ¿å¤ævirtualåoverrideçå ç¹æ»ç»ã
- åç±»å¯ä»¥ç´æ¥ä½¿ç¨åºç±»ä¸çprotectedä¸çåéåå½æ°ã
- åºç±»å½æ°æ²¡å virtualï¼åç±»æç¸åå½æ°ï¼å®ç°çæ¯è¦çãç¨åºç±»æéè°ç¨æ¶ï¼è°ç¨å°çæ¯åºç±»çå½æ°ï¼ç¨åç±»æéè°ç¨æ¶ï¼è°ç¨å°çæ¯åç±»çå½æ°ã
- åºç±»å½æ°å äºvirtualï¼åç±»æç¸åå½æ°ï¼å®ç°çæ¯éåãç¨åºç±»æéæåç±»æéè°ç¨æ¶ï¼è°ç¨å°çé½æ¯åç±»çå½æ°ã
- å½æ°å ä¸overrideï¼å¼ºå¶è¦æ±åç±»ç¸åå½æ°éè¦æ¯èå½æ°ï¼èä¸å¿ é¡»éæ°å®ç°ï¼å¦åä¼ç¼è¯æ¥éã
- åç±»çvirtualå¯å å¯ä¸å ï¼å»ºè®®å overrideä¸å virtualã
- åºç±»ä¸ç纯èå½æ°ï¼virtual void play() = 0;ï¼å¨åºç±»ä¸æ éå¨cppä¸å®ç°ï¼ä½æ¯å¿ é¡»å¨åç±»å®ç°ï¼å¦åç¼è¯æ¥éã
- 继æ¿å¤ææ大ç好å¤å°±æ¯æç¼å ±æ§ï¼å°éç¨çåéåæ¹æ³ä¿¡å·çï¼å ¨é¨æ¾å¨åºç±»ï¼åç±»è´è´£å®ç°èªå·±éè¦çç¹æ®çé¨åå³å¯ã
- å ³äº QTableViewãQTableWidget æ¬åæ´è¡éä¸ææï¼ç½ä¸å¤§å¤æ°é½æ¯é对 QTableWidget çå®ç°ï¼é对 QTableView çä¹é½æ¯éè¿å§ææè éæ°painterå®ç°ã
- åæï¼è®¾ç½®éä¸åå æ ¼èªå¨éä¸æ´è¡ï¼tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
- å®è£ äºä»¶è¿æ»¤å¨ï¼è¯å«å°å½ååæ å¤çæ°æ®æ¨¡åï¼ç¶å设置å½å模åä¸ºé¼ æ æ¬åå¤ç模åå³å¯ãè¿ä¸ªåå·§çåæ³å¯ä»¥èç大éçå·¥ä½ã
- æ 论 QTableViewãQTableWidget é½ç¨æ¤æ¹æ³é½å¯ä»¥ã
- Qtä¸å¦ä½é¿å å第ä¸æ¹çsignalsãslotsçå ³é®åå²çªã
- 第ä¸æ¥ï¼å¨proä¸å ä¸ CONFIG += no_keywords ã
- 第äºæ¥ï¼é¡¹ç®ä¸ä¹åææç signals æ¹æ Q_SIGNALSï¼slots æ¹æ Q_SLOTS çã
- 第ä¸æ¥ï¼å½»åºéæ°ç¼è¯é¡¹ç®ï¼è¿æ ·å°±å ³é®åä¸å²çªäºã
- proä¸åºåä¸åçæä½ç³»ç»å硬件平å°ã
win32 {}
unix {}
//Qt5å¯ä»¥ç´æ¥ç¨ linux{} Qt4åè®°éè¦ç¨ unix:!maxc{}
unix:!maxc{}
linux {}
maxc {}
android {}
wasm {}
//表示64ä½å¹³å°
contains(QT_ARCH, x86_64) {}
//表示armå¹³å°
contains(QT_ARCH, arm) || contains(QT_ARCH, arm64) {}
//ä¸è½åæ³ç´æ¥åæ¢å°å¥ä»¶æå°ä¸ QT_ARCH çä¸ä»ä¹å符
message($$QT_ARCH)
- å¨æ¾ç¤ºè§é¢ç»é¢ä½ç½®çæ¶åï¼ä¸è¬ä¼æä¸ç§æºå¶ä½ä¸ºåèï¼èªå¨æ¨¡å¼(è¶ è¿åçæ¯ä¾ç¼©æ¾å¦ååå¾)ãæ®é模å¼(ä»»ä½å°ºå¯¸é½çæ¯ä¾ç¼©æ¾)ãå¡«å 模å¼(ä»»ä½å°ºå¯¸é½æ伸填å )ãQtä¸å¾çç±»QImageé½æä¾äºç¼©æ¾çç¥çåæ°è®¾ç½®ï¼æ¯å¦Qt::KeepAspectRatio表示çæ¯ä¾ç¼©æ¾ï¼ä½å¾å¤æ¶åæ们éè¦çæ¯è®¾ç½®æ§ä»¶ç大å°ï¼å ¶å®QSize类就æä¾äºå¯¹åºçæ¹æ³scaleä¸é¨è§£å³è¿ä¸ªé®é¢ï¼è¿ä¸ªæ¹æ³å¾å®¹æ被忽è§ã
//缩æ¾æ¾ç¤ºæ¨¡å¼
enum ScaleMode {
//èªå¨æ¨¡å¼(è¶
è¿åçæ¯ä¾ç¼©æ¾å¦ååå¾)
ScaleMode_auto = 0,
//æ®é模å¼(ä»»ä½å°ºå¯¸é½çæ¯ä¾ç¼©æ¾)
ScaleMode_normal = 1,
//å¡«å
模å¼(ä»»ä½å°ºå¯¸é½æ伸填å
)
ScaleMode_fill = 2
};
//ä¼ å
¥å¾ç尺寸åçªä½åºååè¾¹æ¡å¤§å°è¿åå±
ä¸åºå
static QRect getCenterRect(const QSize &imageSize, const QRect &widgetRect, int borderWidth = 2, const ScaleMode &scaleMode = ScaleMode_auto)
{
QSize newSize = imageSize;
QSize widgetSize = widgetRect.size() - QSize(borderWidth * 2, borderWidth * 2);
if (scaleMode == ScaleMode_auto) {
if (newSize.width() > widgetSize.width() || newSize.height() > widgetSize.height()) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
}
} else if (scaleMode == ScaleMode_normal) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
} else {
newSize = widgetSize;
}
int x = widgetRect.center().x() - newSize.width() / 2;
int y = widgetRect.center().y() - newSize.height() / 2;
return QRect(x, y, newSize.width(), newSize.height());
}
//ä¼ å
¥å¾ç尺寸åçªä½å°ºå¯¸å缩æ¾çç¥è¿ååé尺寸çå¾ç
static void getScaledImage(QImage &image, const QSize &widgetSize, const ScaleMode &scaleMode = ScaleMode_auto, bool fast = true)
{
Qt::TransformationMode mode = fast ? Qt::FastTransformation : Qt::SmoothTransformation;
if (scaleMode == ScaleMode_auto) {
if (image.width() > widgetSize.width() || image.height() > widgetSize.height()) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, mode);
}
} else if (scaleMode == ScaleMode_normal) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, mode);
} else {
image = image.scaled(widgetSize, Qt::IgnoreAspectRatio, mode);
}
}
- å ³äºå¨å¤´æ件ä¸å®ä¹å½æ°ä½¿ç¨staticå ³é®åçè¡çæè®ã
- ææ¶åæ们éè¦å°ä¸äºå¸¸ç¨å½æ°åå¨ä¸ä¸ªæ件ä¸ä¾å¾å¤å°æ¹è°ç¨ï¼å¦æåçæ¯ int doxxx{} è¿ç§ï¼å¨ä½ å¤ä¸ªå°æ¹å¼ç¨çæ¶åï¼è¯å®ä¼ç¼è¯æ¥éæ示 âéå¤å®ä¹â çé误ã
- æ¤æ¶ä½ éè¦å¨å½æ°åé¢å ä¸staticå ³é®åï¼åæ static int doxxx{} è¿ç§ï¼è½å¤æ£å¸¸ç¼è¯åè¿è¡ï¼ä»¥ä¸ºä¸åä¸äºå¤§åï¼è¿æ¯æ太年轻ã
- å¦æä» ä» æ¯ä¸ä¸ªç±»ä¸å¨ä½¿ç¨ï¼æè å½æ°ä¸æ²¡æéæåéï¼ä¹ä¸ä¼åºé®é¢ï¼é®é¢å°±å¨static修饰çå½æ°å¨æ¯ä¸ªå¼å ¥å¤´æ件çæ¶åé½ä¼æ·è´ä¸ä»½ï¼å¯¼è´å½æ°éé¢çstaticéæåéä¼éå¤åå§åï¼è¿æ ·å°±ä¸æ£ç¡®äºã
- 为äºè§£å³è¿ä¸ªé®é¢ï¼ç»æåæ³å°±æ¯å¨å¤é¢å¥ä¸ªç±»ï¼ææçå½æ°ååéæ¾å°ç±»ä¸ï¼å®ç¾ï¼åä¹ä¸ä¼ç¡ä¸çäºï¼çé¦ã
- å ³äºC/C++ ä¸çstaticå ³é®åï¼å»ºè®®å¤§å®¶åèè¿ç¯æç« åå¾ https://zhuanlan.zhihu.com/p/37439983ï¼ééç顶ã
//æ件å test.h
//ä¸é¢è¿ä¸ªå½æ° ç¼è¯æ¥éæ示 âéå¤å®ä¹â
void test() {}
//ä¸é¢4个å½æ°å¨æ¯ä¸ªå¼å
¥å¤´æ件çæ¶åé½ä¼è¢«æ·è´ä¸ä»½
static void test1() {}
inline void test2() {}
static inline void test3() {}
inline static void test4() {}
//ä¿è¯æ²¡é®é¢çåæ³
class tt {
void test() {}
static void test1() {}
inline void test2() {}
static inline void test3() {}
inline static void test4() {}
}
- å¨æ°æ®åºæ¥è¯¢ä¸ï¼ä¸è¬ä¼å»ºç«ç´¢å¼ä»¥ä¾¿å å¿«æ¥è¯¢é度ï¼æ¯å¦å¸¸ç¨çæ¡ä»¶å段ä½ä¸ºç´¢å¼å段ãä½æ¯æäºæ¶åå¦ææ¥è¯¢è¯å¥æ²¡å好ï¼å°±ç®whereä¸æç´¢å¼å段ä¹ä¼å¼èµ·å ¨è¡¨æ«æï¼ä¹å°±æ¯è¯´æ ¹æ¬æ²¡ç¨ä¸ç´¢å¼ï¼è¿ç¹è¦ç§¯æçé¿å ã
- 模ç³æ¥è¯¢likeï¼å ¨æ¨¡ç³ like '%...%' åå·¦æ¨¡ç³ like '%...' æ æ³ç´æ¥ä½¿ç¨ç´¢å¼ï¼å³æ¨¡ç³æ¥è¯¢ like '...%' ä¼ä½¿ç¨ç´¢å¼ã
- æ¥è¯¢æ¡ä»¶ä¸å«æis nullçselectè¯å¥æ§è¡æ ¢ï¼is not null æ¶æ°¸è¿ä¸ä¼ä½¿ç¨ç´¢å¼ï¼ä¸è¬æ°æ®é大ç表ä¸è¦ç¨is nullæ¥è¯¢ã
- ä¸çäºæä½ç¬¦ <> å != ä¼éå¶ç´¢å¼ï¼å¼èµ·å ¨è¡¨æ«æï¼å³ä½¿æ¯è¾çå段ä¸æç´¢å¼ã
- whereåå¥ä¸æ¯è¾ç两个æ¡ä»¶ï¼ä¸ä¸ªæç´¢å¼ï¼ä¸ä¸ªæ²¡ç´¢å¼ï¼ä½¿ç¨oråä¼å¼èµ·å ¨è¡¨æ«æã
- select count(*) from table è¿æ ·ä¸å¸¦ä»»ä½æ¡ä»¶çcountä¼å¼èµ·å ¨è¡¨æ«æã
- in å not in ä¹è¦æ ç¨ï¼å¦åä¼å¯¼è´å ¨è¡¨æ«æï¼è½ç¨ between å°±ä¸è¦ç¨ inã
- ç¨ >= æ¿ä»£ >ï¼æ¯å¦ é«æåæ³ï¼select * from table where id >= 4ï¼ä½æåæ³ï¼select * from table where id > 3ã
- å¦æ表æ°æ®éå¾å°ï¼æ¯å¦å°±å åè¡ï¼è¯·å¿½ç¥ä¸è¿°è¦åï¼å ä¸å ç´¢å¼é®é¢ä¸å¤§ï¼çè³æäºæ¶åå ç´¢å¼åèæ大å¢å äºæ°æ®åºæ件çä½ç§¯ï¼å½±åæ´æ°æ°æ®åºçé度ã
- ç±äºQtå¨ä¸æçæ´æ°æ¢ä»£ï¼åç§ç»ä»¶è½®åä¹å¨å¢å ãæåãè°æ´çï¼æ以æ们å¨ç¼å项ç®çæ¶åï¼å¦ææçæ¬å ¼å®¹çé®é¢ï¼å°±éè¦å¨pro项ç®æ件å代ç æ件ä¸å对åºçå¤æå¤çãæ ¹æ®å¤å¹´çç»éªæ»ç»ï¼ä¸ä¸ªä¸è½çåæ³å°±æ¯å¨proä¸å¢å ä¸ä¸ªDEFINESæ è¯ï¼ç¶åæ ¹æ®è¿ä¸ªDEFINESæ è¯å¼å ¥å¯¹åºæ¨¡åï¼æåå¨ä»£ç ä¸éè¿#ifdefå¤ææ è¯æ§è¡å¯¹åºä»£ç ãç»è¿è¿æ ·åè ¾å ä¸ä½ ç代ç å¯ä»¥å¨ä½çæ¬åé«çæ¬ç¼è¯è¿è¡ã
//pro pri æ件
//ä¸é¢è¡¨ç¤ºä¸»çæ¬>4åçæ¬>6 å³çæ¬>=5.7
greaterThan(QT_MAJOR_VERSION, 4) {
greaterThan(QT_MINOR_VERSION, 6) {
DEFINES += qchart
}}
//ç±äºQt6çåå¸ä»¥å以åQt7ãQt8çï¼å
æä¸é¢è¿ä¸ªå¤ææ¯ä¸å¤çç
//ä¸é¢è¡¨ç¤ºQt主çæ¬>5 å³çæ¬>=6.0
greaterThan(QT_MAJOR_VERSION, 5) {
DEFINES += qchart
}
//å¤ææå®ä¹å导å
¥å¯¹åºæ¨¡å
contains(DEFINES, qchart) {
QT += charts
}
//代ç æ件
#ifdef qchart
//è¦æ§è¡ç代ç
#endif
//æ¥é
Qt项ç®ä»£ç åç°å¦ä¸å¤æå¯ä»¥ç´æ¥å¤æ大äºæ个çæ¬èä¸éè¦å¤æ¬¡å主çæ¬å¤æ
//ä¸é¢ç¨ 4.8/5.5/5.7/5.15/6.2/6.7 ççæ¬æµè¯å
¨é¨æ£å¸¸
//è¿æ个缺é·å°±æ¯å¿
é¡»ä¿è¯ä¼ å
¥ç大çæ¬å·å¿
é¡»å°äºçäºç¬¬ä¸ä¸ªåæ°ä¸æå®ç大çæ¬å·
greaterThan(QT_MAJOR_VERSION, 4)|greaterThan(QT_MINOR_VERSION, 7) {
message(å½åçæ¬å¤§äº4.7)
}
//åæ ·ç¨ä½å¯¹ç¼è¯å¨çæ¬å¤æè¿æ QT_GCC_MAJOR_VERSION/QT_GCC_MINOR_VERSION/QT_CLANG_MAJOR_VERSION/QT_CLANG_MINOR_VERSION
//æå°å½åç¼è¯å¨å称 QMAKE_CXX ç»æ cl / g++
//æå°å½åç¼è¯å¨å®ä¹ QMAKE_COMPILER_DEFINES ç»æ _MSC_VER=1800 _WIN32 / __GNUC__ WIN32
//æå°ç¼è¯å¨çæ¬ MSVC_VER ç»æ msvc2013=12.0 / msvc2015=14.0
- å¨ä½¿ç¨QChartå¾è¡¨æ§ä»¶çæ¶åï¼ä½ ä¼åç°é»è®¤çè¾¹è·å¥½å¤§ï¼å¾å¤æ¶åæ们å¸æè½æ¾ç¤ºæ´å¤çä¿¡æ¯ï¼ç´§ååççé¢ï¼æ以éè¦è®¾ç½®è¾¹è·ã
//设置èæ¯åºååè§è§åº¦
chart->setBackgroundRoundness(0);
//设置å
è¾¹çè¾¹è·
chart->setMargins(QMargins(0, 0, 0, 0));
//设置å¤è¾¹çè¾¹è·
chart->layout()->setContentsMargins(0, 0, 0, 0);
- Qtå ç½®äºæ°æ®å缩å解åçåè½ï¼å¦æéå°å¾çãé³é¢æ°æ®ãæ件ç转base64ä¼ è¾è¿ç§ï¼éç¨qCompresså缩å大æ¦å¯ä»¥èç30%çæ°æ®ä¼ è¾éï¼å缩æ§è½å¯è§ãåææ¯åæ¹é½æ¯Qtç¨åºï¼å 为æ¶å°æ°æ®çæ¶åè¿è¦ç¨qUncompress解ååºæ¥ï¼æ对åºç°çã
//åéçæ¶åå缩ä¸æ°æ®
QByteArray buffer = "...";
buffer = qCompress(buffer);
socket->write(buffer);
//æ¶å°æ°æ®åå¡å¿
è®°å¾å
解åå使ç¨
QByteArray data = socket->readAll();
data = qUncompress(data);
25ï¼241-250
- QStringç±»æ¯æ个人认为Qtææç±»ä¸çç²¾åï¼å°è£ çæ å¯æåãå ç½®äºåç§è¿å¶æ°æ®ç转æ¢ï¼æ¯å¦å°æ°æ®è½¬æ10è¿å¶ã16è¿å¶æ¾ç¤ºï¼æè å°10è¿å¶ã16è¿å¶æ°æ®è½¬æå符串æ¾ç¤ºãè¿éå¾å®¹æ忽ç¥çä¸ç¹å°±æ¯ï¼å¾å¤äººä»¥ä¸ºå°±æ¯æ¯æ2è¿å¶ã10è¿å¶ã16è¿å¶ä¹ç±»çï¼å ¶å®ä¸æ¯çï¼éé¢å®ç°äº 2-36 ä¹é´çä»»æè¿å¶è½¬æ¢ï¼å¯ä»¥èªè¡ç¿»é æºç æ¥çå®ç°ã
char data[2];
data[0] = 0x10;
data[1] = 25;
//è¾åº 2è¿å¶æ¾ç¤º "10000" "11001"
qDebug() << "2è¿å¶æ¾ç¤º" << QString::number(data[0], 2) << QString::number(data[1], 2);
//è¾åº 5è¿å¶æ¾ç¤º "31" "100"
qDebug() << "5è¿å¶æ¾ç¤º" << QString::number(data[0], 5) << QString::number(data[1], 5);
//è¾åº 10è¿å¶æ¾ç¤º "16" "25"
qDebug() << "10è¿å¶æ¾ç¤º" << QString::number(data[0]) << QString::number(data[1]);
//è¾åº 16è¿å¶æ¾ç¤º "10" "19"
qDebug() << "16è¿å¶æ¾ç¤º" << QString::number(data[0], 16) << QString::number(data[1], 16);
- QtSql模åå°è£ äºåç§æ°æ®åºæä½ï¼ä½¿å¾Qtæä½åç§æ°æ®åºé常çç®åï¼æ¯æåç§åæ ·çæ°æ®åºï¼æåºç¡çODBCæ¹å¼ä¹æ¯æè¿æ¥å°åç§æ°æ®åºãæ个å¾å®¹æ忽è§çè¦ç¹å°±æ¯å¨è¿æ¥sqlserveræ°æ®åºçæ¶åï¼ä½ ä¼åç°ç¬¬ä¸æ¹çæ°æ®åºå·¥å ·ä¹æ²¡æé ç½®æ°æ®åºï¼ä½æ¯å¯ä»¥è¿æ¥æåï¼èå¨Qtä¸ç常è§æ°æ®åºè¿æ¥åæ³å´ä¸è¡ï¼é£æ¯å ä¸ºä½ ä»£ç åéäºï¼è¦ç¨å¦å¤ä¸ç§åæ³ã
//è¿æ¥sqliteæ°æ®åº
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
//åªéè¦æå®æ°æ®åºæ件çç»å¯¹è·¯å¾å³å¯
database.setDatabaseName("d:/test.db");
//è¿æ¥mysqlæ°æ®åº
QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
database.setDatabaseName("test");
database.setHostName("127.0.0.1");
database.setPort(3306);
database.setUserName("root");
database.setPassword("root");
//è¿æ¥å°sqlserveræ°æ®åº
//æ¹å¼ä¸éè¿odbcæ°æ®æºï¼åææ¯å¿
é¡»é
置好æ°æ®æºã
QSqlDatabase database = QSqlDatabase::addDatabase("QODBC");
database.setDatabaseName("æ°æ®æºå称");
database.setUserName("sa");
database.setPassword("123456");
//æ¹å¼äºéè¿é©±å¨å符串ï¼æ éé
ç½®æ°æ®æºã设置æ°æ®åºå称就带äºä¸»æºå°å端å£åç¨æ·ä¿¡æ¯ææåé¢è¿äºè®¾ç½®ä¸éè¦ï¼å¼ºç建议æ¨èæ¤æ¹æ³ã
QSqlDatabase database = QSqlDatabase::addDatabase("QODBC");
QStringList list;
list << QString("DRIVER={%1}").arg("SQL SERVER");
list << QString("SERVER=%1,%2").arg("127.0.0.1").arg(1433);
list << QString("DATABASE=%1").arg("test");
list << QString("UID=%1").arg("sa");
list << QString("PWD=%1").arg("123456");
database.setDatabaseName(list.join(";"));
//è¿æ¥å°postgresqlæ°æ®åº
QSqlDatabase database = QSqlDatabase::addDatabase("QPSQL");
database.setDatabaseName("test");
database.setHostName("127.0.0.1");
database.setPort(5432);
database.setUserName("postgres");
database.setPassword("123456");
//è¿æ¥å°oracleæ°æ®åº
QSqlDatabase database = QSqlDatabase::addDatabase("QOCI");
database.setDatabaseName("test");
database.setHostName("127.0.0.1");
database.setPort(1521);
database.setUserName("system");
database.setPassword("123456");
//è¿æ¥å°äººå¤§éä»kingbaseæ°æ®åºï¼å
æ ¸å°±æ¯postgresqlï¼
QSqlDatabase database = QSqlDatabase::addDatabase("QPSQL");
database.setDatabaseName("test");
database.setHostName("127.0.0.1");
database.setPort(54321);
database.setUserName("SYSTEM");
database.setPassword("123456");
//éè¿odbcæ°æ®æºè¿æ¥å°åç§æ°æ®åºï¼åææ¯å¿
é¡»é
置好æ°æ®æºï¼åªéè¦è®¾ç½®æ°æ®åºå称为æ°æ®æºçå称ï¼å¡«åç¨æ·ååå¯ç å°±è¡ï¼å
¶ä»ç主æºå°åå端å£ä¸éè¦ã
QSqlDatabase database = QSqlDatabase::addDatabase("QODBC");
database.setDatabaseName("æ°æ®æºå称");
database.setUserName("system");
database.setPassword("123456");
- å¦æä¿¡å·æ§½å ³èå½æ° connect(obj, SIGNAL(), this, SLOT()); æ§è¡å¤æ¬¡åä¼éå¤å ³èï¼æå³çä¼æ§è¡å¤æ¬¡ï¼ï¼èåæ¶ä¿¡å·æ§½å ³èå½æ° disconnect(obj, SIGNAL(), this, SLOT()); åªéè¦æ§è¡ä¸æ¬¡å°±å¯ä»¥å°ä¹åå ³èçï¼åªææ¯éå¤å ³èè¿ï¼å ¨é¨æ¸ é¤ãå¾å¤åå¦è ä¼éå°ä¸ºä»ä¹ç¹ä¸ä¸å± ç¶æ§è¡å¤æ¬¡çåå å°±å¨è¿éï¼å¾å¯è½ä»£ç ä¸åäº on_objName_clicked(); è¿ç§Qtå ç½®èªå¨çæå ³èç槽å½æ°ï¼ç¶åèªå·±åå¨ä»£ç ä¸è°ç¨ connect ç»å®äºä¸æ¬¡ï¼å¯¼è´éå¤ç»å®ãæ个建议ï¼å ¶å®Qtå¯ä»¥è¿æ»¤ä¸å¦ææ¯å®å ¨ä¸æ ·çç»å®å认为æ¯ä¸ä¸ªèä¸æ¯å¤ä¸ªã
//为äºä¿è¯æ°¸è¿åªæä¸ä¸ªå
³èå¯ä»¥å¨å
³èåé¢æ§è¡ä¸æ¬¡åæ¶å
³è
disconnect(obj, SIGNAL(), this, SLOT());
connect(obj, SIGNAL(), this, SLOT());
//ç»è¿ç¾¤é大佬æ示ï¼åæ¥connect第äºä¸ªåæ°å¡« UniqueConnection å°±å¯ä»¥é¿å
è¿ä¸ªé®é¢ï¼æç
§å®æ¹æ档说æè¿ä¸ªåæ°ä¼è¿æ»¤éå¤çä¿¡å·ã
connect(obj, SIGNAL(), this, SLOT(), Qt::UniqueConnection);
- éè¿å¯¹Qtèªå¸¦Examplesçæºç ç ç©¶ä½ ä¼åç°ï¼è¶å¾åççæ¬ï¼è¶å欢ç¨æºè½æéQScopedPointeræ¥å®ä¹å¯¹è±¡ï¼è¿æ ·æ个好å¤å°±æ¯ç¨çå°æ¹åªç®¡newå°±è¡ï¼ä¸ç´newä¸å»ï¼ä¸ç¨æ å¿èµæºéæ¾é®é¢ï¼æºè½æéä¼ç»ä½ å¨åéçæ¶æºéæ¾ï¼ç¸å½äºå¯ä»¥å°äºä¸è¡ä»£ç xxx->deleteLater(); ï¼èä¸é¿å ä¸å¿ è¦ç麻ç¦ï¼ä¸ç¶å¾å¤å°æ¹ä½ è¦å¤æ if (!xxx) çä¸å¯¹è±¡æ¯å¦okã
QWidget *widget;
//ç¨çå°æ¹å
new
widget = new QWidget;
//ç¨å®éæ¾å¯¹è±¡
widget->deleteLater();
//æºè½æéåæ³
QScopedPointer<QWidget> widget;
//åªç®¡new尽管newä¸ç¨ç®¡éæ¾
widget.reset(new QWidget);
-
å¦ææ§ä»¶ä¸åå¨å¸å±ï¼å¨è°ç¨setLayoutéæ°è®¾ç½®å¸å±çæ¶åï¼ä¼æ示 QWidget::setLayout: Attempting to set QLayout ... ä¹ç±»çä¿¡æ¯ï¼è¯´æ¯å·²ç»åå¨äºå¸å±ï¼éè¦å é¤ä¹åçå¸å±æè½éæ°è®¾ç½®å¸å±ï¼æéçQtæ¨èçæ¯è°ç¨ layout()->deleteLater() æ¹æ³å»å é¤å¯¹è±¡ï¼æ´å®å ¨ï¼ä½æ¯å¨è¿éä¸èµ·ä½ç¨ï¼ä½ éè¦ç¨ delete layout() æ¥å é¤ï¼çå®å¥æªã
-
å¨ç¼åç±»ä¸ææ¶åéè¦å¯¹åéè¿è¡èµå¼ååå¼ï¼è¿æ¶åä¸è¬ç¨ setxxxãgetxxx ä¹ç±»çå½æ°è¿è¡å¤çï¼èä¸å¾å¾éé¢å°±ä¸è¡ä»£ç ï¼è¿æ¶åä½ å¯è½ä¼æè为ä½ä¸ç´æ¥å°åéæ¹æpublicæ´é²åºæ¥ä½¿ç¨ï¼è¿å¯ä»¥ç两个å½æ°å è¡ä»£ç ãå ¶å®ç¨set getè¿æ ·å¤ç主è¦è¿æ¯ä¸ºäºæå±æ§ï¼æ¯å¦åæå¦æéè¦å¯¹èµå¼è¿è¡è¿æ»¤å¤çï¼æè 该åéåªå 许读åä¸çä¸ä¸ªï¼å¦æä¹åæ¯ç´æ¥ä½¿ç¨çåéå¤ï¼å使ç¨çå°æ¹é½è¦å»ä¿®æ¹è§åï¼åèåå¾å¾ç³ç³ã åèæç« https://blog.csdn.net/ChineseSoftware/article/details/122923485 ã
-
å ³äºå¦ä½å¿«éç»æ线ç¨ï¼è°ç¨terminateæ´åç»æ容æåºé®é¢ãä¸è¬æ¥è¯´æ们é½æ¯éç¨æ å¿ä½æ¥ç»æ线ç¨ï¼ä½æ¯å¦ææ§è¡è¿ç¨ä¸çå½æ°å¾èæ¶ï¼æè å¨runä¸msleepä¼æ¯çæ¶é´è¿ä¹ ï¼å®¹æ导è´è¦å¾é¿ä¸æ®µæ¶é´æè½æ£ç¡®åæ¢ï¼æ¤æ¶å¯ä»¥èèä¸ä¸ªçç¥å°±æ¯åå²çº¿ç¨æ§è¡ä½ï¼å¦ææ¯å½æ°ä½èæ¶å¯ä»¥å¨èæ¶çå½æ°ä½ä¸å¢å åæ¢æ å¿ä½çå¤æï¼ä½¿å ¶å¿«éè·³åºï¼å¦ææ¯å»¶æ¶æ¶é´è¿ä¹ å¯ä»¥å°å»¶æ¶æ¶é´æåæå¤ä¸ªå°çæ¶é´è½®çï¼æ¯ä¸ªå°çä¼æ¯é´éé½å¤æåæ¢æ å¿ä½ï¼è¿æ ·ä¹å¯ä»¥æ大å 快线ç¨æ£å¸¸éåºçé度èä¸ç¨çå¾ å¤ªä¹ ã
void Thread::run()
{
while (!stopped) {
doTask();
//ä¸é¢è¿ä¸ªå»¶æ¶å¤ªä¹
导è´éåºå¾æ
¢
//msleep(3000);
//ç¹ææ¯æ¬¡å个å°å»¶æ¶æ¯æ¬¡é½å»å¤ææ å¿ä½çå¯ä»¥æ大å å¿«å
³éé度
int count = 0;
while (!stopped) {
msleep(100);
count++;
//å¦æå°äº30次=30*100=3000毫ç§ä¹è·³åº
if (count == 30) {
break;
}
}
}
stopped = false;
}
void Thread::doTask()
{
while(1) {
if (stopped) {
return;
}
doTask1();
doTask2();
}
}
- Qtä¸å¦ææå®äºåä¸ä¸ªç¶ç±»çªä½ï¼åæ§ä»¶é½ä¼è¦çå¨è¯¥ç¶ç±»çªä½ä¸ï¼è¿å°±éè¦è®¾ç½®çªå£å°é¨ä»¶è¦çé®æ¡ä¸å±å 顺åºã
//Qt对æå
±åç¶ç±»çªä½çæ§ä»¶ä¼åå°äºæè´ï¼ä¸é¢çæäº1000个widgetææ°å¢ä¸å°3mbçå
åã
for (int i = 0; i < 1000; ++i) {
QWidget *w = new QWidget(this);
w->setGeometry(0, 0, 100, 100);
w->show();
}
QWidget *w1, *w2, *w3;
//å°w1æ§ä»¶ç§»å°æåé¢ç¸å½äºå¨è¯¥ç¶çªä½ä¸ç½®é¡¶
w1->raise();
//å°w1æ§ä»¶ç§»å°æåé¢ç¸å½äºå¨è¯¥ç¶çªä½ä¸ç½®åº
w1->lower();
//å°w1æ§ä»¶ç§»å°w2æ§ä»¶ä¸é¢
w1->stackUnder(w2);
- å½æä»¬å ³éçªä½çæ¶åï¼æéçæ¥è¯´é½ä¼æ§è¡å¯¹åºçªä½çææå½æ° ~MainWindow() ä¹ç±»çï¼è¿æ¯çæ³ç¶æï¼å½ä½ ççªä½è¿å¼¹åºäºåçªä½ï¼å°±ç®ä½ å ³éäºä¸»çªä½ï¼ä¼åç°åçªä½ä¾ç¶å¨ï¼èä¸æ ¹æ¬æ²¡æå»ææ主çªä½ï¼å¯¹åºçåçªä½ä¹æ²¡æ设置 setParent ï¼é常æ åµä¸ï¼æ们é½æ¯å¸æå ³éäºä¸»çªä½ï¼å¯¹åºåçªä½èªå¨å ³éï¼è¿ä¸ªæ¶åæä¹åå¢ï¼ä½ éè¦éè½½ closeEvent æ¿å°å ³éæ¶æ¯ï¼ä¸»å¨å»æåçªä½éæ¾ã
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void closeEvent(QCloseEvent *);
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QLabel *lab;
};
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
lab = new QLabel;
lab->resize(400, 300);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::closeEvent(QCloseEvent *)
{
//å
æåçªä½éæ¾
lab->deleteLater();
}
void MainWindow::on_pushButton_clicked()
{
lab->show();
}
- å ³äºQtä¸ sendEvent å postEvent 主å¨æ¨¡æåéé¼ æ é®çäºä»¶çå ç¹è¯´æã
- sendEventæ¯é»å¡å¼ï¼ä»£ç ä¼ç«å³æ§è¡ï¼æ¯ææ 空é´åå 空é´äºä»¶å¯¹è±¡çåéï¼å±é¨å¯¹è±¡ånewåé ç对象ï¼ã
- postEventæ¯éé»å¡å¼ï¼ä¼åéå°äºä»¶éåä¸çå¾ å¤çï¼åªæ¯ææ å 空é´äºä»¶å¯¹è±¡çåéï¼newåé ç对象ï¼ã
- newåé çäºä»¶å¯¹è±¡è¢«å¤çåï¼ä¼ç±Qtå é¨èªå¨æ§æ¯ï¼ä¸ç¨æ å¿ã
- çæ¶é´å å¯éé¢ç¹çè°ç¨ï¼æ¨èç¨postEventï¼æ¾å ¥äºä»¶éåé常å®å ¨ãå¦åç¨sendEventå¾å®¹æ导è´å´©æºã
//ä¸é¢è¿ä¸ªä¼ç«å³æ§è¡
QResizeEvent event(size(), size());
QApplication::sendEvent(this, &event);
//ä¸é¢è¿ä¸ªä¼ç«å³æ§è¡
QResizeEvent *event = new QResizeEvent(size(), size());
QApplication::sendEvent(this, event);
//ä¸é¢è¿ä¸ªä¸ä¼æ¥éä½æ¯ä¹ä¸ä¼æ§è¡å 为äºä»¶å¯¹è±¡æ¯å±é¨åé
QResizeEvent event(size(), size());
QApplication::postEvent(this, &event);
//ä¸é¢çæ¹å¼é常å®å
¨
QResizeEvent *event = new QResizeEvent(size(), size());
QApplication::postEvent(this, event);
26ï¼251-260
- ä»å¤©å¨ä¸ä¸ªå¤´æ件ä¸ï¼åç° #ifdef Q_OS_WIN #ifdef Q_CC_MSVC ä¹ç±»çé½å¤±æäºï¼æå¾å·®ç¹æç人çäºãç»åè¿ä¹å类似çæè®åï¼ææ¥åæ¥æ¯æ²¡ææåå¼å ¥ qglobal.h 头æ件导è´çãåè®°å¦æè¦ä½¿ç¨Qtçä¸è¥¿ï¼åªææ¯æåºç¡çæ è¯å®å®ä¹ Q_OS_WIN ä¹ç±»çï¼é½è¦ä¿è¯è¯¥åé¢è³å°å å«äº qglobal.h ï¼å¦åé½æ¯å¤±è´¥çãå¾å¤äººåæä¸æ ·å¤©çç以为ç¼è¯å¨ä¼èªå¨å¤çã
//å¿
é¡»è¦å
å¼å
¥è¿ä¸ªå¤´æ件
#include "qglobal.h"
#ifdef Q_OS_WIN
...
#else
...
#endif
#ifdef Q_CC_MSVC
#pragma execution_character_set("utf-8")
#endif
- æä¸ä¸ªåºæ¯ç»å¸¸éå°ï¼é£å°±æ¯å¨ç¬¦åæ个æ¡ä»¶ä¸ï¼å»¶æ¶ä¸æ®µæ¶é´å»æ§è¡ä¸æ®µä»£ç ï¼å¦æçæ¶é´å 触åå¤æ¬¡åä¸éè¦é¢ç¹æ§è¡ï¼åªéè¦æ§è¡ä¸æ¬¡å°±è¡ãå¦æéæ©ç¨QTimer::singleShotæ æ³ç»æ¢å·²ç»è§¦åçï¼è¿ä¸ªæ¶åå°±è¦ä¸»å¨å®ä¾åä¸ä¸ªå次å®æ¶å¨ï¼æ¯æ¬¡è°ç¨åé½åæ¢ä¹åçï¼åªè¦æ¯è¿æ²¡æ§è¡é½ä¼åæ¶ï¼ï¼å®ç¾è§£å³ã
//QTimer::singleShot(1000, thread, SLOT(xxx()));
static QTimer *timer = NULL;
if (!timer) {
timer = new QTimer;
QObject::connect(timer, SIGNAL(timeout()), thread, SLOT(xxx()));
timer->setSingleShot(true);
timer->setInterval(1000);
}
timer->stop();
timer->start();
-
ææ¶åæ们åç°æ§ä»¶è®¾ç½®éæåèæ¯åæé»è²ï¼ä½ å¯ä»¥å°è¯è®¾ç½®éæ度å¼1èä¸æ¯å®å ¨éæ0ï¼è¿æ ·çèµ·æ¥æ¯éæçä½æ¯åä¿çäºçªä½çç¹æ§ãå¦ææ³è¦ä¸åºç¨ç³»ç»é´å½±è¾¹æ¡å¯ä»¥è®¾ç½®å±æ§ w.setWindowFlags(w.windowFlags() | Qt::NoDropShadowWindowHint);
-
Qtä¸çäºä»¶è¿æ»¤å¨ç¸å½äºä¸è½å¤§æ³ï¼ç»æç§å¯æ¦å¨ï¼ï¼å°¤å ¶æ¯å¯¹æ´ä¸ªåºç¨ç¨åºå®è£ äºä»¶è¿æ»¤å¨ï¼åå¯ä»¥æ¿å°ææçäºä»¶ãæ¯å¦å¯ä»¥æ¿å°ç³»ç»æ é¢æ é¼ æ æä¸æ¾å¼ï¼å¯¹ææéè¦ç§»å¨çæ è¾¹æ¡çªä½ç»ä¸æ¦æªè¿è¡ç§»å¨å¤çã个人建议ä¸å°ä¸ä¸å¾å·²ä¸å»ºè®®ä½¿ç¨ï¼æä¸å®æ§è½æèï¼æ¯ç«è¿ä¸ªæ¯ä»æåæºå¤´æ¦æªäºä»¶ï¼æå³çææçäºä»¶é½ä¼å°è¿éè¿ä¸éãå¦æä½ å¨æ¶å°å¯¹åºäºä»¶åè¿åäºä¸å®èæ¶çå¤çï¼å¾å®¹æå°±å¡ä¸»äºUI主线ç¨ã
void AppInit::start()
{
qApp->installEventFilter(this);
}
bool AppInit::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::NonClientAreaMouseButtonPress) {
qDebug() << "ç³»ç»æ é¢æ æä¸";
} else if (event->type() == QEvent::NonClientAreaMouseButtonRelease) {
qDebug() << "ç³»ç»æ é¢æ æ¾å¼";
}
QWidget *w = (QWidget *)watched;
if (!w->property("canMove").toBool()) {
return QObject::eventFilter(watched, event);
}
static QPoint mousePoint;
static bool mousePressed = false;
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->type() == QEvent::MouseButtonPress) {
if (mouseEvent->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = mouseEvent->globalPos() - w->pos();
}
} else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
mousePressed = false;
} else if (mouseEvent->type() == QEvent::MouseMove) {
if (mousePressed) {
w->move(mouseEvent->globalPos() - mousePoint);
return true;
}
}
return QObject::eventFilter(watched, event);
}
- linuxä¸å¯æ§è¡æ件é»è®¤ä»ç³»ç»ç¯å¢åéæ¥æ¾å¨æåºï¼èwindowsä¸é»è®¤æ¯ä»å¯æ§è¡æ件æå¨ç®å½æ¥æ¾ï¼æ以ææ¶å为äºç»ä¸ï¼å¸æå¨æåºå°±æå®æ¾å¨å¯æ§è¡æ件åä¸ç®å½ä¸æè ç¸å¯¹ç®å½æ¯å¦libæ件夹ï¼è¿å°±éè¦ç¼è¯çæ¶ååç¹æ®è®¾ç½®ï¼å¨pro项ç®æ件ä¸æå®rpathï¼ä¹å¯ä»¥ç¨å½ä»¤æè 第ä¸æ¹å·¥å ·è¿è¡è®¾ç½®ï¼ï¼æå®å¥½ä»¥åé»è®¤å ä»æå®çrpathæ¥æ¾å¨æåºæ¯å¦å¨ï¼ä¸å¨ç¶ååå»ç¯å¢åéä¸çè·¯å¾æ¥æ¾ã
linux {
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/lib\'"
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/../lib\'"
}
- é»è®¤QDialogçªä½å³ä¸è§æ个æ伸尺寸çææï¼éè¿å®å¯ä»¥å¯¹çªä½æ伸大å°ï¼è¿ä¸ªæ§ä»¶å¾å®¹æ被éå¿ä½æ¯åç»å¸¸å¯ä»¥çå°ï¼ä»çååå«QSizeGripï¼å¯ä»¥éè¿setSizeGripEnabledæ¥å¯ç¨æè ç¦ç¨ï¼ä¹å¯ä»¥ç¨qss对å¤è§è¿è¡è®¾ç½®ã
QSizeGrip {
image:url(:/image/sizegrip.png);
width:10px;
height:10px;
}
- å¨æäºæ²¡æopenglç¯å¢çQtå¼åä¸ï¼æ¯å¦ä¸äºåµå ¥å¼æ¿å为äºèçèµæºæ²¡æç¼è¯openglæ以ä¸ä¼æopenglç¸å ³ç头æ件ï¼å¨ç¼è¯é¡¹ç®è¿ç¨ä¸å¯è½éå°æ示 GLES3/gl3.h: No such file or directoryï¼å°½ç®¡ä½ ç项ç®ä¸ä¹æ²¡æç¨å°openglçä»»ä½ä¸è¥¿ï¼é£æ¯å ä¸ºä½ å å«äºä¸ä¸ªå¤§æ¨¡å #include "QtWidgets" ï¼èè¿ä¸ªå¤§æ¨¡åä¸å å«äº #include "qopenglwidget.h" ï¼ä½ éè¦åçæ¯å¨å¼å ¥å¤§æ¨¡ååé¢å ä¸è¡ã
//ä¸é¢ä¸¤ä¸ªå®ä¹çå
·ä½éæ±è°æ´
#define QT_NO_OPENGL
#define QT_NO_OPENGL_ES_3
#include <QtWidgets>
- å¯ä»¥éè¿è®¾ç½®è¿æ»¤æºå¶ï¼å°ä»£ç ä¸çé¨åæå°ç±»å«å±è½æï¼æ¯å¦åªä¿çqdebugæå°çä¿¡æ¯ï¼ä¹å¯ä»¥å°Qtå é¨ç±»çè¦åä¿¡æ¯å±è½ï¼åªä¿çèªå·±ç¨åºåçæå°ä¿¡æ¯ã
//代ç åå¨mainå½æ°æåé¢
int main(int argc, char *argv[])
{
QLoggingCategory::setFilterRules("*.critical=false");
QApplication a(argc, argv);
}
//ä¸é¢è¡¨ç¤ºå°ææçdebugæå°ä¿¡æ¯å±è½
QLoggingCategory::setFilterRules("*.debug=false");
//ä¸é¢æç»æå° 222
qDebug() << "111";
qInfo() << "222";
//ä¸é¢è¡¨ç¤ºå°ææçæå°ä¿¡æ¯å±è½
QLoggingCategory::setFilterRules("*=false");
//ä¸é¢å¯ä»¥å°ææè¦åæ示å±è½(Qtå
é¨ç±»ä¸åºç°çè¦åä¿¡æ¯é½ç¨çè¿ä¸ªqErrnoWarning对åºçå°±æ¯critical)
QLoggingCategory::setFilterRules("*.critical=false");
//æ¯æå¤ä¸ªè§ååæ³(æé¨åè¦åä¿¡æ¯ç¨çqWarningæ以ä¹è¦å è¿å»)
QLoggingCategory::setFilterRules("*.critical=false\n*.warning=false");
- å®æ¹çQtå®è£ å åºæ¬ä¸é½å¸¦äºåç§é«çº§æ¨¡åæ¯å¦æµè§å¨æ¨¡åwebengine以åå¤åªä½æ¨¡åqï¼æäºåµå ¥å¼çç¯å¢æè å家æä¾å¥½çQtç¯å¢ï¼æªå¿ æè¿äºæ¨¡åï¼éè¦åç¬æå½ä»¤å®è£ ã
//å¦ææ¾ä¸å°é³é¢è¾å
¥è¾åºè®¾å¤éè¦æ§è¡ä¸é¢è¿ä¸ªå½ä»¤
sudo apt-get install libqt5multimedia5-plugins
//å®è£
æµè§å¨æ¨¡å
sudo apt-get install libqt5web*
//ä¹å¯ä»¥ä¸æ¬¡æ§å®è£
ææ
sudo apt-get install libqt5*
- 项ç®å¤§äºä»¥åï¼ç»å¸¸éè¦å°æäºç±»åæåä¾ç±»ï¼å¨æ´ä¸ªé¡¹ç®ä¸å¯ä¸åå¨ï¼ä¾å¤ä¸ªå°æ¹ä½¿ç¨ï¼å¦æä¸ä¸ªå°±ä¸ä¸ªç±»éè¦åæåä¾æ¨¡å¼ï¼é£ç´æ¥åå¨é£ä¸ªç±»ä¸å³å¯ï¼å¦æç±»å¤äºçè¯ï¼ä¼åç°é½æ¯ä¸äºéå¤çå®ä¹ä»£ç ï¼æ¤æ¶å¯ä»¥èèç¨ä¸ªå®å®ä¹ï¼ä¼ å ¥ç±»åå³å¯ï¼ä»£ç éè½ç¶å°äºå¯è½ç»©æä½äºï¼ä½æ¯æ°´å¹³æåäºã
#ifndef QTSINGLETON_H
#define QTSINGLETON_H
#include <QScopedPointer>
#include <QMutex>
#define SINGLETON_DECL(Class) \
public: \
static Class *Instance(); \
private: \
Q_DISABLE_COPY(Class) \
static QScopedPointer<Class> self;
#define SINGLETON_IMPL(Class) \
QScopedPointer<Class> Class::self; \
Class *Class::Instance() { \
if (self.isNull()) { \
static QMutex mutex; \
QMutexLocker locker(&mutex); \
if (self.isNull()) { \
self.reset(new Class); \
} \
} \
return self.data(); \
}
#endif // QTSINGLETON_H
//使ç¨çæ¶åå¨å¤´æ件åå®ç°æ件åå ä¸è¡ä»£ç å³å¯
#include "qtsingleton.h"
class Form : public QWidget
{
Q_OBJECT SINGLETON_DECL(Form)
}
SINGLETON_IMPL(Form)
Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form)
{
ui->setupUi(this);
}
27ï¼261-270
-
代ç ä¸å¤æå½åQtåºæ¯32ä½è¿æ¯64ä½ï¼ç¨QSysInfo::WordSize=32/64ã
-
QTreeViewæ§ä»¶è®¾ç½®å·¦ä¾§branch å¾æ 大å°ï¼æ æ³éè¿qss设置ï¼ä¸è½å¤§æ³æ¥çæºç å¾ç¥æ§å¶å®½åº¦æååå³äºindentationåæ°ï¼indentationçé»è®¤å¼æ ¹æ®ç³»ç»ç¯å¢ä¸åèä¸åï¼æ¯å¦1080På辨çä¸æ¯20ï¼ä½ è¦æ¾å¤§å¯ä»¥éè¿ setIndentation(30) æ¥è®¾ç½®ã
-
å¨å¯¹é项å¡æ§ä»¶QTabWidgetè®¾ç½®æ ·å¼è¡¨çæ¶åï¼å¾å¤äººå¸æè½åæ类似æµè§å¨æè èµæºç®¡çå¨ä¸ä¸é¢é项å¡çæ ·åï¼å°±æ¯éä¸çtabä¸è¾¹å·¦å³ä¸¤è¾¹æå ç²çº¿æ¡ï¼åºé¨ç©ºç½çåé¢æ¿å½¢æä¸ä½ï¼æå¾å¤æ¹æ³ï¼æ¹æ³ä¸å°±æ¯æåºè¾¹å®½åº¦ä¸º0ï¼æ¹æ³äºå°åºè¾¹é¢è²è®¾ç½®æåé¢æ¿é¢è²ä¸æ ·ï¼æ¹æ³ä¸å°tabçåºè¾¹è¾¹è·è®¾ç½®æè¾¹æ¡çè´æ°ï¼margin-bottom:-3pxï¼ï¼è¿æ ·çèµ·æ¥å°±æ¯åé¢æ¿è为ä¸ä½äºã
//ä¸é¢å ç§åå«å¯¹åºé项å¡ä¸åä½ç½®çææ
//注æQt5.12çæ¬åtabbaré项å¡å·¦å³åè¿æ¥ç
QTabWidget::pane:top{top:-1px;}
QTabWidget::pane:bottom{bottom:-1px;}
QTabWidget::pane:left{right:-1px;}
QTabWidget::pane:right{left:-1px;}
-
å¨linuxä¸ç¼è¯å¨æåºæ件ï¼å¯è½ä¼çæä¸å 软è¿æ¥æ件ï¼å¾æ ä¸æ个å°ç®å¤´/libuntitled.so/libuntitled.so.1/libuntitled.so.1.0libuntitled.so.1.0.0ï¼ï¼å¾å¤æ¶åçèµ·æ¥å¾ç¦ï¼ä¹ æ¯äºwindowsä¸å°±çæä¸ä¸ªæ件ï¼ä½ åªéè¦å¨ä½ çproæè priä¸å ä¸ä¸è¡ CONFIG += plugin å³å¯ï¼è¿æ ·åªä¼çæä¸ä¸ªlibuntitled.soæ件ã2023-4-2è¡¥å ï¼è¿å¯ä»¥ä½¿ç¨ CONFIG += unversioned_libname unversioned_soname æ¥å®ç°ï¼unversioned_libnameç¨æ¥å»ælibçå个çæ¬å·ï¼unversioned_sonameç¨æ¥å»æé¾æ¥éççæ¬å·ï¼ä¸å è¿ä¸ªçè¯å°½ç®¡çæçæ¯libuntitled.soï¼ä½æ¯é¾æ¥ç¼è¯çæ¶åè¿ä¼æ¥éæ示ä¾èµå¸¦çæ¬å·çï¼ãå ·ä½æç« å¯ä»¥åè https://blog.csdn.net/gongjianbo1992/article/details/129889588 ã
-
å ³äºQtå¨çº¿å®è£ è¿ç¨ä¸åºç°æ¥éæ示ï¼ä¸è½½âhttp://mirrors.aliyun.com...âæ¶åºç°ç½ç»é误 ç解å³æ¹æ³ï¼æå¼å½ä»¤è¡è¿è¡å®è£ ç¨åºï¼æ¯å¦C:\Users\Administrator>D:\Qt\Qt6\MaintenanceTool.exeï¼åé¢ä¸»å¨å ä¸åæ° --mirror https://mirrors.cloud.tencent.com/qtï¼å®æ´å½ä»¤è¡æ¯ C:\Users\Administrator>D:\Qt\Qt6\MaintenanceTool.exe --mirror https://mirrors.cloud.tencent.com/qtï¼å车è¿è¡å³å¯ãåçä¹å¯ä»¥æ¢æå½å å ¶ä»çéåå°åï¼è ¾è®¯äº https://mirrors.cloud.tencent.com/qt /é¿éäº https://mirrors.aliyun.com/qtï¼ï¼ææ¶åéåçæ´æ°è¦æ ¢ä¸äºï¼å¯ä»¥è¿å ¥å°ç®å½ https://mirrors.aliyun.com/qt/online/qtsdkrepository/ çä¸æ没æ对åºççæ¬ã
-
ä»Qt6.4çæ¬å¼å§å¤åªä½æ¨¡åæä¾äºffmpegä½ä¸ºå端解ç 使ç¨ï¼6.5çæ¬é»è®¤å°±æ¯ffmpegï¼ï¼å¯ä»¥éè¿è®¾ç½®ç¯å¢åéæ¥æ´æ¹ä½¿ç¨åªç§å端解ç ï¼å¨mainå½æ°ç第ä¸è¡ qputenv("QT_MEDIA_BACKEND", "ffmpeg"); ç®åå·²ç¥çé®é¢æ¯å¦æéç¨ffmpegåææ¶ä¸æ¯æä¸æç®å½ä»¥åä¸æå称ï¼å¨6.5.1ä¿®å¤äºï¼ï¼å¦æä¸å®è¦æ¯æä¸æåéè¦æ¹æwindowsã
//设置å端解ç 为ffmpeg/ææç³»ç»é½æ¯æ
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
//windowsç³»ç»ä¸ç¨
qputenv("QT_MEDIA_BACKEND", "windows");
//linuxç³»ç»ä¸ç¨
qputenv("QT_MEDIA_BACKEND", "gstreamer");
//macç³»ç»ä¸ç¨
qputenv("QT_MEDIA_BACKEND", "darwin");
//androidç³»ç»ä¸ç¨
qputenv("QT_MEDIA_BACKEND", "android");
-
ä¸ææ¡æ§ä»¶QComboBoxé»è®¤ä¼æ ¹æ®itemçå符宽度è°æ´ä¸ææ¡ç宽度ï¼æ¯å¦å ¶ä¸æ个itemææ¬å¾é¿ï¼åä¸ææ¡ä¼åçå¾å®½ï¼çè³ææ´ä¸ªçé¢æ大çèµ·æ¥åå½¢çæè§ï¼ææ¶åæ们ä¸å¸ææ¯è¿æ ·ï¼æå¤ä¸ªæ¹æ³å¯ä»¥å»æï¼æ¹æ³ä¸å°±æ¯è®¾ç½®ä¸ææ¡çæ伸çç¥ä¸ºQSizePolicy::Ignoredï¼ç¶åå°ä¸ææ¡æ¾å°ä¸ä¸ªå®¹å¨ä¸ï¼ä¿è¯å®¹å¨å¸å±ä¸çå ¶ä»æ§ä»¶é½æ¯æåºå®å°ºå¯¸æè fixå¡«å 尺寸ï¼è¿æ ·ä¸ææ¡å°±æ¯é»è®¤èªå¨æ伸çèä¸ä¿è¯ä¸ä¼è·çitemç宽度å宽ãè¿ä¸ªæ¹æ³å¹¶ä¸å好ï¼å 为éè¦è°æ´å®¹å¨å¸å±ä¸å ¶ä»æ§ä»¶çæ伸çç¥ï¼æä½³æ¹æ³å°±æ¯è®¾ç½® ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); ï¼å½itemå®½åº¦è¶ è¿çæ¶åä¸é´é¨åä¼èªå¨çç¥å·æ¾ç¤ºï¼è¦çå°±æ¯è¿ä¸ªææï¼ä¸ºäºä½¿å¾æ´ä¸ªå ¨å±é½è½åºç¨ï¼å¯ä»¥æ ·å¼è¡¨è®¾ç½® qApp->setStyleSheet("QComboBox{qproperty-sizeAdjustPolicy:AdjustToMinimumContentsLengthWithIcon}"); å³å¯ï¼æ´ä¸ªé¡¹ç®ä¸ææä¸ææ¡é½ä¼èªå¨åºç¨è¿ä¸ªçç¥ã
-
ç¨QSettingsç±»ä¿åfloatç±»åçæ¶åï¼å 容ä¼åæ @Variant å¼å¤´çä¸ä¸ªå¼ï¼åé¢æ ¹æ¬çä¸æä»ä¹å¼ï¼æ¯å¦ 1.0 = @Variant(\0\0\0\x87?\x80\0\0) ä¸ä¸ªé常å¥æªçå¼ï¼è¿æ ·çè¯å¦ææ³ç´æ¥ä¿®æ¹é ç½®æ件æ¥æ´æ¹åæ°å°±æ ä»ä¸æãæ两个åæ³è§£å³é®é¢ï¼åæ³ä¸å°±æ¯å¨åå ¥å¼çæ¶å强å¶è½¬æ¢æQStringç±»åæ°æ®å³å¯ï¼set.setValue("SaveVideoRatio", QString::number(SaveVideoRatio));ï¼åæ³äºå°±æ¯å°floatåæ°ç±»åæ¹ædoubleï¼æ¯å¦ float SaveVideoRatio æ¹æ double SaveVideoRatioï¼æ¨èæ¹æ³ä¸ï¼ä¸ç¨æ´æ¹æ°æ®ç±»åï¼å°±æ¹å¨ä¸è¡å³å¯ï¼èä¸doubleæ°æ®ç±»åç精度ä¸ä¸æ ·ï¼æ¯å¦ float i = 0.1 ä¼åæ double i = 0.10000000149011612 ãå¨Qt6ä¸å½»åºä¿®å¤äºè¿ä¸ªé®é¢ï¼ä¸éè¦è½¬æ¢ã
-
大æ¦ä»Qt5.12å¼å§ï¼æ°å¢äºå¹³å°å¤è§æ件platformthemesï¼æå³çæå åå¸çæ¶åéè¦å¸¦ä¸ä»æè½åºç¨ç³»ç»å±é£æ ¼çå¤è§æ ·å¼ï¼å¦æä¸å¸¦ï¼å¨winä¸å¯è½æ¯windows2000é£æ ¼çå¤èå¤è§ï¼çèµ·æ¥é常诧å¼ã
-
ææ¶åæ们设置å¼æºè¿è¡ç¨åºåï¼å¦æ该ç¨åºç¨åç¨QProcessçæ¹å¼è°ç¨äºç¨åºBï¼èç¨åºBåéè¦è¯»åç®å½ä¸çé ç½®æ件ï¼æ¤æ¶ä½ ä¼åç°æ ¹æ¬è¯»åä¸å°ï¼å 为å¼æºåçé»è®¤ç®å½ä¸å¨å¯æ§è¡æ件æå¨ç®å½ï¼å¦ææ们æ¯åå»ç¨åºè¿è¡çé£å°±ä¸åå¨è¿ä¸ªé®é¢ï¼ä¼èªå¨å°å¯æ§è¡æ件æå¨ç®å½ä½ä¸ºå½åç®å½ãï¼æ以æ们éè¦æ§è¡ä»£ç QDir::setCurrent(qApp->applicationDirPath()); 主å¨è®¾ç½®å½åç®å½å¨åªï¼åè¯æä½ç³»ç»ãQProcessä¸æ个setWorkingDirectoryæ¬äººä¹åç§å¯¹æ¯æµè¯è¿ï¼å¯¹å¼å¯å¯å¨åçç¨åºè°ç¨QProcessæ æï¼å¿ é¡»ç¨QDir::setCurrentãä½æ¯æ个åéçï¼é£å°±æ¯ä¸æ¦è°ç¨äºQDir::setCurrentï¼åä½ çç¨åºä¸çç¸å¯¹ç®å½é½ä¼ä»è®¾ç½®çè·¯å¾ä¸åï¼å¯è½ä¼å¯¼è´æå¤çç»æã
28ï¼271-280
- ç¼ç¨çè¿ç¨ä¸ç»å¸¸éå°éè¦å°QString转æchar *æè const char *çæ åµï¼å¨è½¬æ¢æQByteArrayåè°ç¨.data()æè .constData()å½æ°è¿è¡è½¬æ¢ï¼è¿ééè¦æ³¨æçæ¯ï¼å¦æ转æ¢ç±»åæ¯const char *尽管ç¨data()ä¸ä¼åºéï¼ä¼ç»ä½ èªå¨è½¬æ¢ï¼ä½æ¯è¿æ¯ä¸å»ºè®®ï¼å 为深æ·è´äºä¸ä»½ï¼ç论ä¸å¢å äºå åå¼éï¼å¦æå符串é¿åº¦å°è¿å¥½ï¼ä¸æ¦å¾é¿ï¼è¿ä¸ªå¼éæºå¤§ï¼è¿æ¯ä¸ªå¥½çç¼ç¨ä¹ æ¯ã
//æ¥é
代ç å¾ç¥dataå½æ°æ两个éè½½
inline char *QByteArray::data()
{ detach(); return d->data(); }
inline const char *QByteArray::data() const
{ return d->data(); }
inline const char *QByteArray::constData() const
{ return d->data(); }
QByteArray data = "abc";
//æ·±æ·è´
char *d1 = data.data();
//æ·±æ·è´
const char *d2 = data.data();
//æµ
æ·è´
const char *d3 = data.constData();
//æ·±æ·è´
test(data.data());
//æµ
æ·è´
test(data.constData());
void test(const char *data)
{
}
//è³äºä»ä¹æ¶åè°ç¨.data()ä¼æµ
æ·è´ï¼é
·ç 大佬说æ¯å½QByteArray被const修饰çæ¶å
const QByteArray data;
//æµ
æ·è´
const char *d = data.data();
//é
·ç 大佬补å
ï¼èªQt 5.7çæ¬ä»¥æ¥ï¼å¼å
¥äºqAsConstå½æ°ï¼ä¸ç¨äºæ è转æ¢ã
//è¿ä¸ªå½æ°å®ç°äºC++17æ åä¸çstd::as_const()å½æ°çåè½ï¼å°ä¸ä¸ªé常éçå·¦å¼è½¬ä¸ºå¸¸éçå·¦å¼ã
//å¢å qAsConstå½æ°æ¯ä¸ºäºQtèªå·±çéconst ç容å¨è½å®ç°C++11æ åçåºäºèå´ç循ç¯ã
//该å½æ°ä¸»è¦ç¨äºqt容å¨å¨éå¼å
±äº«ä¸ä¸è¢«detachã
QString s = "abc";
//ä¸é¢ä¼æ·±æ·è´å¼èµ·æ§è½æ失
for (QChar ch : s)
//ä¸ä¼æ·±æ·è´
for (QChar ch : qAsConst(s))
//ä¸é¢ä¹æ¯æµ
æ·è´ï¼ä½æ¯å¨ç¼ç¨æ¶ãå¨ç°å®ä¸ï¼å£°æ为constå¾å¾ä¸å®¹æåå°ã
const QString s;
for (QChar ch : s)
//æ»ç»ï¼å¯¹Qtèªå·±å®ç°ç容å¨å¦ï¼QVectorãQMapã QHashãQLinkedListãQListçï¼å¦æä¸å®è¦ç¨åºäºforï¼var : containerï¼èå´ç循ç¯ï¼å请ç¨å¦ä¸å½¢å¼ï¼
for (var : qAsConst(container))
-
æ°ççQt6.5å¨ubuntuä¸ç¼è¯è¿è¡ç¨åºåä¼æ示 qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. ï¼æ æ³æ£å¸¸å¼¹åºçªä½ç¨åºï¼ä½ éè¦ä¸»å¨å®è£ xcbçç¸å ³åºãsudo apt install libxcb*
-
æäºåºæ¯ä¸æ们éè¦å¨ QApplication a(argc, argv); åé¢æ§è¡ä¸äºå¤çï¼æ¯å¦ QApplication::setAttribute å°±å¿ é¡»å¨æåé¢æ§è¡ï¼èå¾å¤æ¶åè¿ä¸ªè®¾ç½®çåæ°ä¸è½æ¹åæ»ï¼æ¯ç«ç°åºçç¯å¢åå·®ä¸å«ï¼å¸æéè¿é ç½®æ件æ¥é ç½®ï¼é£ä¹é®é¢æ¥äºï¼è¯»åé ç½®æ件ä¸è¬éè¦æå®è·¯å¾æè½æ£å¸¸è¯»åå°ï¼å¦ææ¯ ./ è¿ç§ï¼å¾å¯è½æªå¿ æ¯åºç¨ç¨åºçå½åè·¯å¾ï¼å¦æä½ æ¯åå»è¿è¡çç¨åºï¼é£è¯å®æ¯åºç¨ç¨åºçå½åè·¯å¾ï¼ä¸æ¯åå»è¿è¡é£å°±æ¯ç³»ç»ç¯å¢ä¸çå½åè·¯å¾ï¼æå³çä½ å¼æºå¯å¨æè ç¨systemãQProcessçæ¹å¼å¨å¼æºåè°ç¨å¯å¨çè¯ï¼å°±æªå¿ æ£ç¡®äºã为äºä¿è¯è¿ä¸ªè·¯å¾çæ£ç¡®ï¼å¿ é¡»ä»mainå½æ°ç argv 第ä¸ä¸ªå¼è·åï¼éè¿æ¥é Qtèªèº«ä»£ç ä¸è·åè·¯å¾ï¼ä¹æ¯ä»è¿ä¸ªåæ°è·åã
//ç¨åºæåé¢è·ååºç¨ç¨åºè·¯å¾åå称
static void getCurrentInfo(char *argv[], QString &path, QString &name);
//ç¨åºæåé¢è¯»åé
ç½®æ件èç¹çå¼
static QString getIniValue(const QString &fileName, const QString &key);
static QString getIniValue(char *argv[], const QString &key, const QString &dir = QString());
void QtHelper::getCurrentInfo(char *argv[], QString &path, QString &name)
{
//å¿
é¡»ç¨fromLocal8Bitä¿è¯ä¸æè·¯å¾æ£å¸¸
QString argv0 = QString::fromLocal8Bit(argv[0]);
QFileInfo file(argv0);
path = file.path();
name = file.baseName();
}
QString QtHelper::getIniValue(const QString &fileName, const QString &key)
{
QString value;
QFile file(fileName);
if (file.open(QFile::ReadOnly | QFile::Text)) {
while (!file.atEnd()) {
QString line = file.readLine();
if (line.startsWith(key)) {
line = line.replace("\n", "");
line = line.trimmed();
value = line.split("=").last();
break;
}
}
}
return value;
}
QString QtHelper::getIniValue(char *argv[], const QString &key, const QString &dir)
{
QString path, name;
QtHelper::getCurrentInfo(argv, path, name);
QString fileName = QString("%1/%2%3.ini").arg(path).arg(dir).arg(name);
return getIniValue(fileName, key);
}
int main(int argc, char *argv[])
{
int openGLType = QtHelper::getIniValue(argv, "OpenGLType").toInt();
QtHelper::initOpenGL(openGLType);
QApplication a(argc, argv);
...
}
- å½æ们对QTableView/QTreeView/QTableWidget/QTreeWidgetæè¡éä¸åï¼ä¼åç°æäºåå æ ¼è®¾ç½®çåæ¯è²è¢«è¦çäºï¼æ¯å¦è®¾ç½®ç红è²ï¼ä¸æ¦éä¸å°±åæäºç½è²ï¼è¿è¯å®ä¸æ¯æ们æ³è¦çï¼éè¦ç¨èªå®ä¹å§æå°å ¶å»æã
class ItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit ItemDelegate(QObject *parent = 0);
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#include "itemdelegate.h"
ItemDelegate::ItemDelegate(QObject *parent) : QItemDelegate(parent)
{
}
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem option2 = option;
QColor color = index.data(Qt::ForegroundRole).value<QColor>();
if (color.isValid() && color != option.palette.color(QPalette::WindowText)) {
option2.palette.setColor(QPalette::HighlightedText, color);
}
QItemDelegate::paint(painter, option2, index);
}
//对ææåå
æ ¼è®¾ç½®è¯¥å§æ
ui->tableWidget->setItemDelegate(new ItemDelegate);
- æäºæ¶åæ们éè¦å¨é¡¹ç®æ件æ¯å¦pro/priä¸è¯å«å½åQtå¥ä»¶æ¯å¦åå¨æ个模å以åæ¯å¦å¼å ¥è¿æ个模åï¼åå¨åå¼å ¥ï¼åæ¶ä¹å¸æ代ç ä¸ä¹è½è¯å«æ¯å¦å¼å ¥è¿æ个模åæ¯å¦sql模åï¼å¤æååè¿è¡å¯¹åºçå¤çã
//项ç®æ件ä¸å¤æ
//å¦æå½åå¥ä»¶ä¸æmultimedia模ååå¼å
¥multimedia模å
qtHaveModule(multimedia) {QT += multimedia}
//å¨é¡¹ç®æ件ä¸å·²ç»éè¿ QT += multimedia å¼å
¥è¿æ¨¡å
contains(QT, multimedia) {}
//代ç æ件å¤æ
#ifdef QT_MULTIMEDIA_LIB
qDebug() << "multimedia module is enabled";
#else
qDebug() << "multimedia module is not enabled";
#endif
-
对MDIçªä½åºå设置èæ¯é¢è²éæï¼ä¼åç° QMdiArea{background:transparent;} æ æï¼åªææ¯æå®é¢è² QMdiArea{background:#ff0000;} æè QMdiArea{background-color:#ff0000;} é½ä¸è¡ï¼è¿å°±å¾æ è¯äºï¼åæ¥è¦ç¨å¼±å±æ§æºå¶æè¡ãQMdiArea{qproperty-background:transparent;}
-
å½æ ·å¼ä¸å¯ç¨äºç¦ç¨æ ·å¼ *:disabled{xxx} çæ¶åï¼ä¼åç°MDIåçªä½æ æ³æ伸äºï¼è¿åºè¯¥æ¯Qtå é¨çBUGï¼æä¹è§£å³å¢ï¼åªéè¦éæ°è®¾ç½®MDIè¿ä¸ªç±»å«çç¦ç¨æ ·å¼çè¾¹æ¡æ ·å¼å³å¯ãQMdiSubWindow:disabled{border:8px solid rgba(0,0,0,0);}
-
ç¨QProcessæ§è¡å½ä»¤æè å¯å¨å¯æ§è¡æ件ï¼é»è®¤åæ³ä¸æ¯æå¸¦ç©ºæ ¼çè·¯å¾ï¼æ¯å¦ Program Files ï¼éè¦å¨è¿ä¸ªè·¯å¾ååå ä¸åå¼å·æè¡ï¼ä¼°è®¡å¯è½å é¨ä¼ç¨ç©ºæ ¼åå²å符串导è´è§£æ失败ãæ®éè·¯å¾å ä¸å¼å·ä¹è½æ£å¸¸æ§è¡ï¼æ以为äºç¡®ä¿ä»¥é²ä¸ä¸ï¼ç»ä¸å ä¸å¼å·å³å¯ã
QString cmd = "c:/Program Files/a.exe";
//ä¸é¢è¿ä¸ªä¼æ§è¡å¤±è´¥
QProcess::startDetached(cmd);
//ååå ä¸å¼å·å°±å¯ä»¥æ£å¸¸æ§è¡
cmd = "\"" + cmd + "\"";
QProcess::startDetached(cmd);
- å¨å¾ªç¯ä¸åå¼ï¼ä¸´æ¶åéçå®ä¹å°½éå¨å¾ªç¯å¤å±å®ä¹ï¼æ¯æ¬¡å¨å¾ªç¯éå±å®ä¹ä¼å¢å å¼éï¼ç¹å«æ¯å¤æç±»åæ¯å¦QString(åºç¡ç±»åæ¯å¦int/boolå·®å«ä¸å¤§)ï¼å¾ªç¯æ¬¡æ°è¶å¤ï¼æ§è½å·®å«è¶å¤§ã
void MainWindow::on_pushButton_clicked()
{
QElapsedTimer timer;
timer.start();
QString s;
QString text = "abc";
for (int i = 0; i < 10000; ++i) {
s = text.at(0);
}
qDebug() << "æ¹å¼1" << timer.nsecsElapsed();
}
void MainWindow::on_pushButton_2_clicked()
{
QElapsedTimer timer;
timer.start();
QString text = "abc";
for (int i = 0; i < 10000; ++i) {
QString s = text.at(0);
}
qDebug() << "æ¹å¼2" << timer.nsecsElapsed();
}
//debug模å¼ä¸æ¹å¼1æ¯æ¹å¼2å¿«6å+
//release模å¼ä¸æ¹å¼1æ¯æ¹å¼2å¿«30å+
- Qtçå±æ§æºå¶é常强大ï¼é¤äºå¯ä»¥ç¨æ¥æ§å¶æ ·å¼è¡¨ï¼ä¹å¯ä»¥å¾æ¹ä¾¿çç¨æ¥ä¼ å¼ï¼æ¯å¦qmlä¸çå¼ä¼ éï¼ææ¶åæ们åäºä¸ä¸ªéç¨ç±»ï¼å¸æè¿ä¸ªç±»å¯ä»¥åå¾å¤äºæ ï¼ä½æ¯åå¸æå ¶ä¸æä¸äºç¹æ®åéååå¼ï¼ä¸ç§åæ³æ¯ç´æ¥å®ä¹ç§æåéï¼æä¾get/setæ¥å£å½æ°ï¼è¿æä¸ç§å·æçåæ³å°±æ¯ç¨å±æ§setProperty/propertyï¼ç¶Qtå é¨ä»å 对象æ°æ®å±é¢èªå·±ç®¡çï¼è¿æ ·ä¸ç¨å¨ç±»ä¸å对åºçåéåget/setå½æ°ãä½æ¯è¯å®ææ§è½æèï¼æ§è½ä¸è¯å®æ¯åéä½ï¼æ以è¦çå ·ä½çå®é éæ±ï¼å¦æä¸æ¯é常é¢ç¹çè°ç¨setProperty/propertyï¼éç¨æ§ä¼å çè¯ï¼é£ç¨å±æ§æºå¶ä¼æ´æ¹ä¾¿ã个人æ¨èæ¹å¼ä¸ï¼ç»§æ¿éç¨ç±»ï¼å¨åç±»ä¸å¢å set/getã
void MainWindow::on_pushButton_clicked()
{
QElapsedTimer timer;
timer.start();
for (int i = 0; i < 10000; ++i) {
Test *t = new Test;
//t->setId(i);
//t->setName("test");
t->getName();
}
qDebug() << "æ¹å¼1" << timer.nsecsElapsed();
}
void MainWindow::on_pushButton_2_clicked()
{
QElapsedTimer timer;
timer.start();
for (int i = 0; i < 10000; ++i) {
Test *t = new Test;
//t->setProperty("id", i);
//t->setProperty("name", "test");
t->property("name").toString();
}
qDebug() << "æ¹å¼2" << timer.nsecsElapsed();
}
//对æ¯æµè¯åå
·ä½çåéç±»åæ å
³/intåQStringç±»å产ççæ§è½å·®å«ä¸æ ·
//setPropertyæ¯setxxxæ¹å¼æ§è½å·®3å+
//propertyæ¯getxxxæ¹å¼æ§è½å·®1.3å
29ï¼281-290
-
æ¬åçªä½QDockWidgeté»è®¤å¨æ é¢æ å³é®ä¼å¼¹åºæ¬å模åçæ¾ç¤ºéèèåï¼å¦æéè¦å»æï¼ä¼åç°è®¾ç½®Qt::NoContextMenuæè äºä»¶è¿æ»¤å¨æ¦æªé½æ¯æ æçï¼å¿ 须设置 dockWidget->setContextMenuPolicy(Qt::PreventContextMenu); ã
-
Qtä¸çå¸å±æ个é»è®¤çmarginè¾¹è·å¼åspacingé´è·å¼ï¼å¨æ²¡æ设置该å¼çæ åµä¸ï¼ä¼æ ¹æ®è¿è¡çç¯å¢èªå¨è®¾ç½®è¯¥å¼ï¼æ¯å¦1080På辨çå2kå辨çççµèï¼è¯¥å¼çé»è®¤å¼ä¸ä¸æ ·ï¼å¹¶ä¸æ¯ä½ å¨UI设计çæ¶åå±æ§æ ä¸çå°çå¼ï¼è¿ä¸ªè¦ç¹å«æ³¨æï¼ä½ çå°ç7å¯è½å¨ç®æ å¹³å°è¿è¡çæ¶åæ¯11ï¼å¦æä¸å®è¦æç §ä½ æ³è¦çå¼æ¥è¿è¡ï¼å¯ä»¥éæ°è®¾ç½®å³å¯ï¼è®¾ç½®è¿åªä¸ä¸ªå°±è¯¥å¼æç §è®¾å®çæ¥ãå¦æä¸æ³ä¸ä¸ªä¸ªè®¾ç½®è°æ´å¸å±ä¸çé´è·è¾¹è·ï¼ä½ éè¦ç¨å°ä¸è½å¤§æ³æ ·å¼ä»£çï¼ç»§æ¿QProxyStyleç±»ç¶åéæ°è®¾ç½®æ ·å¼å³å¯ã该æ¹å¼ä¹æ¯å±äºæç级å«çUIå¤è§æ§å¶çç¥ï¼æç»ææçqssæ ·å¼ä¹æ¯è¦éè¿è¯¥æ ·å¼å»ç»å¶çï¼æå³çè¿éä½ å¯ä»¥éæ°å®ä¹åæ§å¶æææ§ä»¶çå¤è§æ ·å¼ï¼é常ç强大ã
//ä¹å¯ä»¥ç»§æ¿Qtå
ç½®çæ ·å¼æ¯å¦ QFusionStyle/QCleanlooksStyle
class QCustomStyle : public QProxyStyle
{
public:
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const {
if (metric == QStyle::PM_LayoutHorizontalSpacing || metric == QStyle::PM_LayoutVerticalSpacing) {
//å°å¸å±ä¸ç横åååç´é´è·è®¾ç½®æ10
return 10;
} else if (metric == QStyle::PM_ButtonMargin) {
//å°æææé®çmarginè¾¹è·è®¾ç½®æ20
return 20;
}
return QProxyStyle::pixelMetric(metric, option, widget);
}
};
qApp->setStyle(new QCustomStyle);
- å »æè¯å¥½çç¼ç¨ä¹ æ¯è³å ³éè¦ï¼å°¤å ¶æ¯å¯¹åéçåå§åï¼å æ¬ä¸äºç±»å¯¹è±¡çå®ä¹åä¹å¡å¿ è®°å¾åå§åï¼å¦åå¨ä¸åå§åçæ¶åï¼é»è®¤å¼é£å¿½ä¸å®ï¼æ¯å¦inté»è®¤å¼å¨debug/releaseä¸ä»¥åä¸åç¼è¯å¨ä¸é»è®¤å¼é½ä¸ä¸æ ·ï¼çè³å¨å¤´æ件å®ä¹ä»¥åå½æ°ä¸å®ä¹é½å¯è½ä¸åçé»è®¤å¼ï¼ä¸é¢è¡¨æ ¼ä¸æ´ççæµè¯çå¼ï¼å¯¹åºçintå¼é£å¿½ä¸å®çã常è§çé»è®¤åå§åå®ä¹å»ºè®® int i = 0; bool b = false; class a = NULL;
çæ¬ | å®ä¹ä½ç½® | debug/release | int | bool |
---|---|---|---|---|
Qt4.7/mingw | 头æ件 | debug | 7077464 | true |
Qt4.7/mingw | 头æ件 | release | 48 | true |
Qt4.7/mingw | å½æ°ä¸ | debug | 2162216 | false |
Qt4.7/mingw | å½æ°ä¸ | release | 0 | false |
Qt5.7/msvc | 头æ件 | debug | -1 | true |
Qt5.7/msvc | 头æ件 | release | -1 | true |
Qt5.7/msvc | å½æ°ä¸ | debug | 1898108572 | false |
Qt5.7/msvc | å½æ°ä¸ | release | 18872512 | true |
Qt6.5/mingw | 头æ件 | debug | -1305540880 | true |
Qt6.5/mingw | 头æ件 | release | -1124044992 | true |
Qt6.5/mingw | å½æ°ä¸ | debug | 0 | false |
Qt6.5/mingw | å½æ°ä¸ | release | 0 | false |
- 对QTableViewè¿è¡å ¨é¨éä¸ãå ¨é¨ä¸éãååéä¸æä½ã
void frmXXX::initAction()
{
QAction *actionAll = new QAction("å
¨é¨éä¸");
QAction *actionInvert = new QAction("ååéä¸");
QAction *actionClear = new QAction("æ¸
空éä¸");
connect(actionAll, SIGNAL(triggered(bool)), this, SLOT(doAction()));
connect(actionInvert, SIGNAL(triggered(bool)), this, SLOT(doAction()));
connect(actionClear, SIGNAL(triggered(bool)), this, SLOT(doAction()));
ui->tableView->addAction(actionAll);
ui->tableView->addAction(actionInvert);
ui->tableView->addAction(actionClear);
ui->tableView->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void frmXXX::doAction()
{
QAction *action = (QAction *)sender();
QString text = action->text();
if (text == "å
¨é¨éä¸") {
ui->tableView->selectAll();
} else if (text == "ååéä¸") {
//æ¾å°ææéä¸çè¡éå
QList<int> rows;
QModelIndexList list = ui->tableView->selectionModel()->selectedRows();
int count = list.count();
for (int i = 0; i < count; ++i) {
rows << list.at(i).row();
}
//å
æ¸
空ææéä¸
ui->tableView->clearSelection();
//ä¸å¨éä¸è¡éåçåéä¸
count = ui->tableView->model()->rowCount();
for (int i = 0; i < count; ++i) {
if (!rows.contains(i)) {
ui->tableView->selectRow(i);
}
}
} else if (text == "æ¸
空éä¸") {
ui->tableView->clearSelection();
}
}
- proæ件ä¸å¤éæ¡ä»¶å¤æï¼åé¢ ! 表示éï¼ä¸é´ | 表示æï¼ä¸¤ä¸ªæ¡ä»¶æ»¡è¶³å ¶ä¸ï¼ï¼ä¸é´ :: 表示ä¸ï¼ä¸¤ä¸ªæ¡ä»¶é½è¦æ»¡è¶³ï¼ã
//表示å®åæè
ioså¹³å°
android|ios {}
//表示éå®ååéioså¹³å°
!android::!ios {}
//表示éiosç³»ç»çmacç³»ç»
maxc:!ios {}
//表示émacç³»ç»çunixç³»ç»
unix:!macx {}
-
å¾å¤æ¶å项ç®è¶åè¶å¤§ï¼ç¶åå°±å¯è½éå°ï¼ææä¹åå¾ç®åçä¸æ®µä»£ç ï¼è¿è¡ç好好çï¼å°±é£ä¹å è¡å åè¡ï¼ä¸ºä½ä¸æ¦å å ¥å°å½å项ç®ä¸ï¼å°±ä¸è¡äºï¼ç¾æä¸å¾å ¶è§£ãä¸è¬éå°è¿ç§æ åµï¼å»ºè®®ä¸¤ç§å¤çåæ³ï¼åæ³ä¸å°±æ¯æ³¨é大æ³ï¼ä»mainå½æ°å ¥å£å¼å§ï¼å°ä¸ç¸å ³çé½æ³¨éæï¼ä»ç»æ£æ¥è¿è¡æµç¨ï¼ç´å°æ¬æ¥ä¸ä¼åºé®é¢ä½æ¯åºé®é¢ç代ç ãåæ³äºå°±æ¯åç¬å个æç®åçæé®é¢çå¯ä»¥ç´æ¥ç¼è¯è¿è¡ç示ä¾ï¼åç¹ä¸ºç®ï¼è¿æ ·æ¥æ¾é®é¢é度快ãå¾å¾ä½ ä¼åç°ï¼åå®è¿ä¸ªç®åçä½ æççæé®é¢ç代ç åï¼è¿è¡æ¯å®å ¨æ£å¸¸çï¼ä»èªå·±å°±å¥½äºï¼æ¤æ¶ä½ å¯ä»¥å®å¿çå»ææ¥å ¶ä»ä»£ç äºã
-
ç°å¨å¾å¤linuxç¨waylandä½ä¸ºæ¡é¢æ¾ç¤ºï¼è¿æ ·ä¼åºç°ä¸ä¸ªé®é¢ï¼ç±äºæ²¡æåæ ç³»ç»ï¼å¯¼è´æ è¾¹æ¡çªä½æ æ³æå¨åå®ä½ï¼ä¸è¬æ¯Qt6å¼å§å¼ºå¶é»è®¤ä¼å ç¨waylandï¼ä¹åQt5æ¯é»è®¤æxcbåä¼å ç¨xcbï¼ï¼ä½ éè¦å¨mainå½æ°åé¢å ä¸è¡ qputenv("QT_QPA_PLATFORM", "xcb");
-
ææ¶å导åºæ件åï¼å¸æç´æ¥æå¼æ件管çå¨å¹¶éä¸åææå¼çæ件ï¼ä»¥ä¾¿ç¨æ·æå¼å¤çï¼éè¦éè¿æ§è¡å½ä»¤æ¥å®ç°ã
QString path = "file:///e:/1.txt";
QProcess::startDetached("explorer.exe", QStringList() << "/select," << path);
-
å¨QTreeWidget/QTableWidgetçä¿¡å·currentItemChangedä¸ï¼æ§è¡å¯¹åºçclearæ¹æ³ä¹ä¼è§¦å该信å·ï¼è¿å°±éè¦ç¹å«æ³¨æäºï¼å¯¹åºè¯¥ä¿¡å·ç两个åæ° current/previous 表示å½åèç¹åä¸ä¸ä¸ªèç¹ï¼ä¸¤ä¸ªåæ°çå¼é½ä¸ºç©ºï¼æ以å¨è¯¥ä¿¡å·å¯¹åºæ§½åæ°å¤çä¸ï¼å¿ é¡»å å¤æ该å¼æ¯å¦ä¸ºç©ºæéï¼ä¸å¤æçè¯å¾å¯è½å¯¼è´ç¨åºå´©æºã
-
å ³äºQtä¸ += å *= çåºå«ï¼+= 表示添å ï¼ä¸ä¼å»éï¼è *= æ¯å»éæ·»å ï¼åå¨åä¸æ·»å ãå»ºè®®ç¨ *=ï¼å°½ç®¡ += ä¹è½æ£å¸¸ä½¿ç¨ï¼æ¯ç«å¤ä¸ä¸ªéå¤çä¸å½±åç¼è¯å¨è¯å«ã
QT += core gui
QT += core gui
message($$QT) //ä¼æå° core gui core gui
QT *= core gui
QT *= core gui
message($$QT) //ä¼æå° core gui
DEFINES += abc
DEFINES += abc
message($$DEFINES) //ä¼æå° abc abc
DEFINES *= abc
DEFINES *= abc
message($$DEFINES) //ä¼æå° abc
30ï¼291-300
- å ³äºå¨proä¸åºålinuxç³»ç»ï¼å¨Qt4å¥ä»¶æ¯ä¸è®¤è¯ linux æ è®°çï¼éè¦ç¨ unix:!macx 表示ãæ以å¦ææå ¼å®¹Qt4çéæ±ï¼å»ºè®®ç¨ unix:!macx 表示ã
//å¦ææ¯linuxä¸çQt4å¥ä»¶åä¸é¢åªä¼æå° unix linux
//å¦ææ¯linuxä¸çQt5/Qt6å¥ä»¶åä¸é¢ä¼æå° linux unix linux
linux {message(linux)}
unix {message(unix)}
unix:!macx {message(linux)}
- 对äºä¸äºè·¨å¹³å°ç项ç®ï¼å°¤å ¶æ¯éè¦å¼å ¥ç¬¬ä¸æ¹åºï¼éè¦æ ¹æ®ä¸åçç³»ç»ä¸åçä½æ°å¼å ¥å¯¹åºæ件夹ä¸çåºæ件ï¼è¿å°±éè¦é¡¹ç®ä¸å»è¯å«å¤çã
#åºåä¸åçç³»ç»
path_sys = win
win32 {
path_sys = win
}
linux {
path_sys = linux
}
#Qt4å¥ä»¶ä¸è®¤è¯linuxæ è®°
unix:!macx {
path_sys = linux
}
macx {
path_sys = mac
}
android {
path_sys = android
}
#åºåä¸åçä½æ° x86_64/amd64/arm64/arm64-v8a
path_bit = 32
contains(QT_ARCH, x.*64) {
path_bit = 64
} else:contains(QT_ARCH, a.*64) {
path_bit = 64
} else:contains(QT_ARCH, a.*64.*) {
path_bit = 64
}
#对åºç³»ç»åä½æ°çåºç®å½
path_lib = lib$$path_sys$$path_bit
//ä¸é¢ä¼æå° libwin32/libwin64/liblinux32/liblinux64/libmac32/libmac64/libandroid32/libandroid64
message($$path_lib)
//使ç¨æ¹å¼
INCLUDEPATH += $$PWD/include
LIBS += -L$$PWD/$$path_lib/ -lxxx
- å½æ£æµå°æäºqtæ建ç¯å¢ä¸æ»¡è¶³å½å项ç®è¦æ±ï¼é¿å 项ç®ç¼è¯å¤±è´¥ï¼å¯ä»¥ç¦ç¨é¡¹ç®ã
#ç¦ç¨é¡¹ç®åæ´ä¸ªé¡¹ç®ç代ç æ件æ¯ç°è²çä¸å¯ç¨ï¼ç¼è¯ä¼è·³è¿ã
lessThan(QT_MAJOR_VERSION, 6) {
error("æä½è¦æ±Qt6æè½ç¨")
}
- å¨ä½¿ç¨QButtonGroupæé®ç»æ·»å æé®çæ¶åï¼å¦æéè¦ä½¿ç¨buttonClicked(int)ä¿¡å·ï¼åæ·»å æé®çæ¶åå¿ é¡»æå¨æå®æé®ç¼å·ï¼å¦åé»è®¤ç¼å·é½æ¯-1ï¼è¿æ ·å¨è§¦åbuttonClicked(int)çæ¶åå¼æ¯è´æ°ï¼å¯¼è´åé¢æä¸ä¸è´ï¼åæ¬ä»¥ä¸ºé»è®¤æç §æ·»å æé®ç顺åºèªå¨éå¢è®¾ç½®ç´¢å¼ï¼å ¶å®ä¸æ¯çï¼ä¸ä¼è¿æ ·å¤çãå¡å¿ è®°å¾æå®æé®ç¼å·ã
QButtonGroup *btnGroup = new QButtonGroup(this);
connect(btnGroup, SIGNAL(buttonClicked(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
//第äºä¸ªåæ°æå®æé®ç¼å·
btnGroup->addButton(ui->btn1, 0);
btnGroup->addButton(ui->btn2, 1);
- å ³äºQCustomplotç»å¾æ§è½çæ¹åã
- å°½éé¿å ç¬å®½åº¦å¤§äº1ç线ï¼é»è®¤æ¯1ï¼å¦æç»å¶çæ°æ®éå¾å¤§ï¼å¼ºçä¸å»ºè®®è®¾ç½®çº¿æ¡å®½åº¦å¤§äº1ï¼æ§è½ä¼å¤§å¤§éä½ã
- é¿å å¤æçå¡«å ï¼ä¾å¦å¨å ·ææ°å个ç¹çå¾å½¢ä¹é´è¿è¡ééå¡«å ã
- å¨å¾è¡¨æå¨æé´ï¼å¯ä»¥è®¾ç½® setNoAntialiasingOnDrag(true)ï¼å¯ä»¥æé«ååºé度ã
- é¿å 使ç¨ä»»ä½ç±»åçalphaï¼éæï¼é¢è²ï¼å°¤å ¶æ¯å¨å¡«å ä¸ã
- å°½éä¸è¦å¼å¯æé¯é½¿ï¼setNotAntialiasedElements(true)ã
- é¿å éå¤è®¾ç½®å®æ´çæ°æ®éï¼ä¾å¦ä½¿ç¨setDataãå¦æ大å¤æ°æ°æ®ç¹ä¿æä¸åï¼ä¾å¦å¨è¿è¡çæµéä¸ï¼è¯·æ¹ç¨addDataã
- æ¨èéè¿QCPGraph::data()访é®åæä½ç°ææ°æ®ï¼æçæ´é«ã
- å¼å¯openglå éï¼ç¬¬ä¸æ¥ï¼å¼å¯æ è®°ï¼å¨proä¸å ä¸ä¸è¡ DEFINES += QCUSTOMPLOT_USE_OPENGL ã第äºæ¥ï¼é¾æ¥openglåºï¼LIBS += -lopengl32 -lglu32 ãæäºQtçæ¬è¿å¯è½éè¦ä¸»å¨å¼å ¥ QT += widgetsãç»è¿å®æµåç°ï¼é«é¢ççç»å¶æ¯å¦60fpså¨å¼å¯openglææ§è½æåï¼ä¸»è¦æ¯éä½äºCPUå ç¨ãä½é¢ççç»å¶è¿å¢å äºCPUå ç¨ãæä»¥å»ºè®®æ ¹æ®å®é åºæ¯æ¥å¤çãè¿ä¸ªåæ°æ®é好åæ å ³ï¼åç»å¶æ°æ®é度æå ³ã
- ç»å¸å ³éæé¯é½¿å±æ§ï¼graph->setAntialiased(false) graph->setAntialiasedFill(false) graph->setAntialiasedScatters(false) ãé»è®¤æ¯trueã
- ç»å¸å¼å¯èªéåºéæ ·ï¼graph->setAdaptiveSampling(true)ãé»è®¤æ¯trueï¼æ以ä¸ç¨ä¸»å¨è®¾ç½®ã
- 使ç¨QDir::setCurrent设置å½åç®å½åï¼ä¼å½±åç¨åºä¸çææç¸å¯¹ç®å½çæ§è¡ï¼å¯¼è´å¯è½çæå¤åçï¼ä¸è¬ç¸å¯¹ç®å½é½é»è®¤æ¯å¯æ§è¡æ件æå¨ç®å½ï¼æ以å¦æç¨åºä¸ä¸ºäºç¹æ®å¤ç临æ¶è°ç¨äºQDir::setCurrent设置è¿ç¸å¯¹ç®å½ï¼å»ºè®®å¤çå®æ以åç«å³åæ¢åæ¥ã
QDir::setCurrent("f:/");
QImage img(":/image/bg_novideo.png");
//ç»æå¾çä¿åå¨f:/1.jpg
img.save("1.jpg", "jpg");
img.save("./1.jpg", "jpg");
//ä¸é¢æ¯æ£ç¡®åæ³
//å
è®°ä½ä¹åçç®å½
QString path = QDir::currentPath();
QDir::setCurrent("f:/");
xxxxxxxæ§è¡ä»»å¡
//éæ°è®¾ç½®åé»è®¤ç®å½
QDir::setCurrent(path);
//ç»æå¾çä¿åå¨å½åç®å½ä¸
img.save("1.jpg", "jpg");
- 大æ¦ä»Qt6.4å¼å§ï¼å¦æ项ç®ä¸åæ¶ä½¿ç¨äºQOpenGLWidgetåQWebEngineæµè§å¨æ§ä»¶ï¼å¯è½ä¼åºç°QWebEngineå è½½ç½é¡µé»å±çæ åµï¼6.4.3å6.5.3çæ¬å¿ ç°ãæ ¹æ®å®ç½çæè¿°https://doc.qt.io/qt-6/qquickwidget.html#graphics-api-support ï¼ä½ éè¦é¢å¤å ä¸è¡ä»£ç ã
#include "qquickwindow.h"
int main(int argc, char *argv[])
{
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
QApplication a(argc, argv);
}
-
ç°å¨ç°å¨æ°ççQté½æ¯éè¦å¨çº¿ä¸è½½ï¼ææ¶åä¸è½½å°ä¸éè¿ç¨ä¼éå°æ示ä¸è½½é误ï¼å¾å¯è½æ¯é¨åæ件模å对åºæå¡å¨æ²¡ææå 导è´çï¼ä¸è¬é½æ¯ä¸äºæ«å°¾å¸¦TPåæ ·ç模åï¼è¿äºæ¨¡åä¸è¬ä¹ä¸ä¼ç¨ï¼æ以å¦ææ³è¦å®è£ æåï¼ä½ éè¦å°éæ©Qtçæ¬åæ件çå°æ¹ï¼æå¼Additional Librariesèç¹ï¼å°é£äºç¨ä¸ä¸çå°¤å ¶æ¯TPç»å°¾çé½ä¸å¾éï¼åå®è£ å³å¯ã
-
Qtä¸å¯ä»¥éè¿qputenvåqgetenvæ¥è®¾ç½®åè·åç³»ç»ç¯å¢åéï¼æ¢å¯ä»¥å¨ä»£ç ä¸è®¾ç½®å¯¹åºçå¼ï¼ä¹å¯ä»¥å¨ç³»ç»ç¯å¢åéä¸è®¾ç½®ï¼æ¯å¦windowsç³»ç»ç¯å¢åéä¸è®¾ç½®ï¼ç¸å½äºå¯ä»¥èªå®ä¹å符串æå®å¼ï¼è¿æ ·çµæ´»æ§å¤§å¤§å¢å¼ºï¼ææ¶åå 为代ç ä¸è½ä¿®æ¹äºï¼å¯ä»¥å°è¯å»è®¾ç½®ä¸ä¸ªQt认è¯çç¯å¢åéå符串å¼æ¥äº§çææãè¿éè¦ç¹å«æ示çæ¯ï¼ç¯å¢åé设置åä¸å®è¦çææè½æ£å¸¸è¯»åå°ï¼æ¯å¦xpç³»ç»è®¾ç½®åå¯è½è¦éå¯æä½ç³»ç»æè½çæï¼è¿æä¸ä¸ªæ¯è¦éå¯QtCreatoræè½è¯å«å°ææ°çç¯å¢åéï¼å¯è½æ¯åäºç¼åæºå¶ã
//设置æ¯ä¸ªçªå£é½æç¬ç«çå¥æ
QApplication a(argc, argv);
a.setAttribute(Qt::AA_NativeWindows);
//ä¸é¢çæ¹æ³æ¯éè¿ä»£ç çæ¹å¼è®¾ç½®/ææ¶åå·²ç»æ¯å¯æ§è¡æ件/æ æ³ä¿®æ¹ä»£ç
//ç»è¿æ¥é
代ç å¾ç¥ä¼ä¼å
éè¿qgetenv读åæ¯å¦æQT_USE_NATIVE_WINDOWSæ å¿
//å¦æåå¨åæç
§QT_USE_NATIVE_WINDOWSåéçå¼è¿è¡èµå¼
//è¿ç§æ¹æ³æ个缺ç¹/å°±æ¯ææçQtç¨åºé½ä¼åºç¨
- å¸å±çsetContentsMarginså½æ°åæ°ä¾æ¬¡æ¯å·¦ä¸å³ä¸ï¼èqssä¸çmarginä¾æ¬¡æ¯ä¸å³ä¸å·¦ï¼å¾å¤äººæ··ææ··ã
31ï¼301-310
- ä»Qt5.2çæ¬å¼å§ï¼QLineEditææ¬æ¡æ§ä»¶æä¾äºsetClearButtonEnabledå½æ°ç¨äºæ¯å¦å¼å¯å³ä¾§çå ³éæé®ï¼è¿ç§æ§ä»¶é常常è§ï¼æ¯å¦è¿å¯ä»¥å¢å 个æç´¢æé®ï¼æä¹æ·»å å¢ï¼å¨5.2çæ¬ä»¥åè¦èªå·±å®ä¹ä¸ä¸ªå¸å±ï¼ç¶ånewä¸ä¸ªæé®æ¾å¨å¸å±å³ä¾§ãå¨5.2çæ¬ä»¥åï¼æä¾äºaddActionéè½½æ¹æ³ï¼ç¨äºæ·»å ä¸ä¸ªå¨ä½å°ææ¬æ¡çåé¢æè åé¢ï¼è¿ç§æ¹å¼ä¼èªå¨çåºè¾¹è·ã
#if (QT_VERSION < QT_VERSION_CHECK(5,2,0))
//ææQtçæ¬é½å
¼å®¹çä¸è½åæ³
QPushButton *searchButton = new QPushButton;
//æ§è¡å¯¹åºçå¤ç
connect(searchButton, SIGNAL(clicked(bool)), this, SLOT(search()));
searchButton->setMinimumWidth(30);
searchButton->setIcon(QIcon(":/main.ico"));
//å®ä¾åå¸å±ç¨äºæ¾ç½®æé®
QHBoxLayout *layout = new QHBoxLayout(ui->lineEdit);
layout->setContentsMargins(0, 0, 1, 0);
//æå®å¯¹é½æ¹å¼æ·»å æé®
layout->addWidget(searchButton, 0, Qt::AlignRight);
//设置ææ¬çå¤è¾¹è·/空åºè·ç¦»æ¾ç½®æé®
ui->lineEdit->setTextMargins(0, 0, searchButton->minimumWidth() + 3, 0);
#else
//æ¨èç¨ä¸é¢è¿ä¸ªæ¹æ³æ´æ¹ä¾¿
QAction *searchAction = new QAction(ui->lineEdit);
//æ§è¡å¯¹åºçå¤ç
connect(searchAction, SIGNAL(triggered(bool)), this, SLOT(search()));
searchAction->setIcon(QIcon(":/main.ico"));
//TrailingPosition表示å³ä¾§/è¿å¯ä»¥æ¯LeadingPosition表示左侧
ui->lineEdit->addAction(searchAction, QLineEdit::TrailingPosition);
#endif
-
大æ¦ä»6.5çæ¬å¼å§ï¼mingwç¼è¯çdebugå¥ä»¶ç¼è¯å¤§åé¼é¼çqcustomplotå¼æºå¾è¡¨æ§ä»¶ï¼ä¼æ示æ¥étoo many sections/file too bigåæ ·ãreleaseå¥ä»¶æè å ¶ä»ç¼è¯å¨é½æ£å¸¸ãä½ åªéè¦å¨proä¸å ä¸ QMAKE_CXXFLAGS += -Wa,-mbig-obj å³å¯ã
-
大æ¦ä»2024å¹´å¼å§ï¼å¨çº¿å®è£ Qtçå·¥å ·é»è®¤ä¸å è½½Qt5çå®è£ å ï¼éè¦å¨å³ä¸è§æ个ä»ä¹ Archive çï¼å¾éä¸ä¸ï¼ç¶ååå» Filter/çé æé®å³å¯ï¼è¿æ ·å·¦ä¾§å°±ä¼å°Qt5çä¹é½æ¾ç¤ºåºæ¥ã估计å®ç½æ¯æ³å¼ºå¶è®©æ们ç¨Qt6ï¼æ ¢æ ¢çæQt5æ·æ±°ãå¯æçæ¯Qt6ä¸æ¯æwin7ï¼èwin7ç®åç¨æ·æ°è¿æ¯å¾å¤çã
-
使ç¨QtçdrawTextç»å¶ææ¬ï¼å¦æ使ç¨ç对åºåæ°æ¯QPointåæ çå½æ°ï¼drawText(const QPoint &p, const QString &s)ï¼å¡å¿ 注æä»æ¯ä»¥å·¦ä¸è§ä½ä¸ºèµ·å§ç¹çï¼Qtææ¡£ä¸ç¹æåäº The y-position is used as the baseline of the fontï¼ï¼è¿ä¸ªåå ¶ä»å¼åæ¡æ¶æ¯å¦C#çé½ä¸åï¼ç论ä¸æç §å±å¹ç»å¶è§åï¼åºè¯¥æ¯å·¦ä¸è§æ对ï¼æ以æ¶åå°åå ¶ä»å¹³å°å¯¹æ¥çæ¶åï¼å»ºè®®éç¨ void drawText(const QRect &r, const QString &text) å½æ°ç»å¶ï¼æå®ä¸ä¸ªåºåãè¿ä¸ªç¥è¯ç¹å¾å®¹æ被忽è§ï¼ä»èé æç¾é¾æ§çåæã
-
å¨linuxä¸ä½¿ç¨webengineæµè§å¨æ¨¡åæå¼ç½é¡µæ¶ï¼æäºç³»ç»å¯è½åºç°å´©æºçç°è±¡ï¼å°±ç®æ¯ç´æ¥ç¼è¯è¿è¡èªå¸¦çæµè§å¨ç¤ºä¾æ¯å¦simplebrowserï¼ä¹æ¯æ æ³æ£å¸¸æå¼ç½é¡µãåå æ¯ä¸ºäºå®å ¨æ§èèï¼æ²ç®±è¿è¡å¥çï¼éè¦è®¾ç½®ä¸ªç¯å¢åéãåªéè¦å¨mainå½æ°æåé¢å ä¸è¡ qputenv("QTWEBENGINE_DISABLE_SANDBOX", "1") å³å¯ã
-
å¨QListWidgetItem设置å¤éæ¡åï¼ææ¶åå¸æå¨åæ¢å¤éæ¡çæ¶åæ个信å·éç¥ï¼ä»¥ä¾¿è¿è¡å¤çï¼å°è¿éä½ ä¼åç°ï¼QListWidgetææä¿¡å·ä¸å¹¶æ²¡æ该信å·ï¼éè¿æ¥é QListWidgetItemçsetCheckStateå½æ°æºç å¾ç¥ï¼ä¼åéä¸ä¸ªdataChangedä¿¡å·ï¼è¯¥ä¿¡å·æ¯QListWidgetçæ°æ®æ¨¡åååºæ¥çï¼äºæ¯å°±å¾å¥½åäºã
void Form::on_listWidget_itemPressed(QListWidgetItem *item)
{
//é¼ æ æä¸åæ¢éä¸ç¶æ
item->setCheckState(item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
}
void Form::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
//为ä»ä¹éè¦éè¿ææ¬åå»æ¾å°èç¹/èä¸æ¯åéä¸çèç¹/å 为ä¸éä¸ä¹å¯ä»¥å¾éåé¢çå¤éæ¡
QListWidgetItem *item;
QString text = topLeft.data().toString();
int count = ui->listWidget->count();
for (int i = 0; i < count; ++i) {
item = ui->listWidget->item(i);
if (item->text() == text) {
break;
}
}
//æ¾å°å¯¹åºèç¹åè¿è¡å¤ç
}
-
è¿ç¨è¿å¾å¤äººçµèè¿ç¨åæé®é¢ï¼åç°ä¸ä¸ªéç ï¼æ¯å¦ææä¿®æ¹äºæ个æ°æ®åºæè é ç½®æ件ï¼ç»æè¿è¡ç¨åºä¸çï¼è¿æ¯æ§çæ°æ®ï¼æ»æ´»é½ä¸è¡ï¼æ¥äºå天ç¨åºï¼å§ç»æ¾ä¸å°é®é¢æå¨ãæç»æ¥å°åæ¥æ¯ç¨åºè¯»åçæä»¶æ ¹æ¬ä¸æ¯ä¿®æ¹è¿çæ件ï¼å 为ç¨æ·çµèç¯å¢ä¸æ好å 份åæ ·ç代ç ç®å½ï¼ä»æå¼çç®å½æ¯å¦å¤ä¸ä»½ï¼æ 论æä¹ä¿®æ¹ï¼å ¶å®é½æ¯åå½åç¨åºæ å ³çï¼æ ¹æ¬æ²¡ææ¹å¯¹å°æ¹ã大æ°æ®ç»è®¡ï¼è¿ç§æ åµè¿çä¸å°ï¼è³å°å äºåä¹ä¸çæ¯ä¾ãæ好å 份æ·è´çæ åµå¾å¤æ¶åé¿å ä¸äºï¼æ¯å¦ä¸ºäºä¸´æ¶å¤ä»½ä»£ç ï¼ä»¥ä¾¿æµè¯æ°ç代ç ãä½æ¯å¡å¿ è®°å¾å½å项ç®åè¿æ·è´ï¼éå°é®é¢çæ¶åå æ£æ¥ç®å½æ¯å¦æ£ç¡®ï¼æ¯å¦æ¯å½åæå¼ç项ç®ä»£ç æå¨ç®å½ã
-
å¨ä½¿ç¨ç¬¬ä¸åºçè¿ç¨ä¸ï¼å½ä½ 使ç¨çåºç§ç±»è¶å¤ï¼ä¼åç°ä¸ä¸ªç°è±¡ï¼æäºåºä¾èµç¼è¯å¨çï¼æ¯å¦opencvï¼å¦æä½ ç¨msvcç¼è¯åºæ¥çåºï¼é£ä½ çç¨åºåªè½ç¨msvcçå¥ä»¶æè½æ£å¸¸é¾æ¥è¯¥åºï¼ä½ è¦æ¯ç¨mingwå»é¾æ¥è¯å®å¤±è´¥çï¼è¦æ³ç¨mingwä¹è½æåé¾æ¥ï¼ä½ åªè½ç¨mingwå»ç¼è¯opencvãå°è¿éä½ æ¯ä¸æ¯ä»¥ä¸ºé½æ¯è¿ä¸ªè§åï¼é£å°±éäºï¼å½ä½ ç¨ffmpegçåºçæ¶åï¼å°±ä¸åå¨è¿ä¸ªé®é¢ï¼å®æ¹ä¸è½½çåºæ件ï¼æ¢è½ç¨msvcä¹è½ç¨mingwå»é¾æ¥ãè¿æ¯å 为ffmpegæ¯çº¯c项ç®ï¼èopencvæ¯çº¯c++项ç®ï¼æ¶åå°ABIçé®é¢ï¼è¿æ¯C++çç¹æ§å¯¼è´çãC++æ¯ä¸ç§å¤æçç¼ç¨è¯è¨ï¼æ¯æ继æ¿åå¤æï¼å æ¤ç¼è¯å¨è¦æ³ä¿è¯åç¡®è°ç¨å½æ°ï¼å°±éè¦ç¡®å®å ¶è°ç¨çº¦å®ï¼å½æ°ååºåãåæ°è¾å ¥ãæ 管ççï¼ãè¿åç±»åååæ°å表ãå¨åä¸ç§æ¶æä¸ä¸åç¼è¯å¨å¯¹æ¤å¯¼åºçè§åä¸ä¸è´ãæ以æ»ç»å°±æ¯ï¼çº¯cç项ç®ç¼è¯åºæ¥çåºä¸ç¨åºåç¼è¯å¨ï¼çº¯c++çéè¦åºåãqtavä½è æ个ææ°åä½mdk项ç®ï¼ä¹æ¯çº¯cåçï¼æä¾äºmingwåmsvcçåºï¼æ 论ä½ç§ç¼è¯å¨ç¼è¯åºæ¥çåºï¼é½åæ¶å ¼å®¹msvcåmingwç¼è¯å¨ï¼è¿å°±æ¯çº¯cçé åã
-
ææ¶åæ们éè¦åå ¥æ件å°ç£çï¼ä½æ¯æäºæ åµä¸ï¼å¦æ对åºç®å½ä¸åå¨ååå ¥å¤±è´¥ï¼éè¦å å¤æç®å½æ¯å¦åå¨ï¼ä¸åå¨åæ°å»ºï¼QDiræä¾äºmkdiråmkpath两ç§æ¹æ³æ¥å建ç®å½ï¼ä»¥å以为è¿ä¸¤ä¸ªæ¯ä¸æ ·çåè½ï¼ç±»ä¼¼äºsizeålengthï¼å ¶å®ä¸æ¯çï¼ç´å°è¿ææåç°äºåºå«ãmkdiråªä¼å建路å¾ä¸çææ«å°¾çç®å½ï¼å¦æç¶ç®å½ä¸åå¨ï¼åå建失败ãèmkpathä¼é级å¤ææ´ä¸ªè·¯å¾çç®å½ï¼ç¶ç®å½ä¸åå¨åå建ç¶ç®å½ï¼ä¾æ¬¡ä¸å»ï¼ä¿è¯æå®çè·¯å¾å建æåï¼å»ºè®®ä½¿ç¨mkpathã
QDir dir;
//å¦æpathç®å½ä¸åå¨ådirç®å½ä¹ä¼å建失败
dir.mkdir("f:/path/dir");
//ä¼å
å建pathç®å½ç¶åå建dirç®å½
dir.mkpath("f:/path/dir");
-
å½ä½ å¨widget项ç®ä¸å°jsæ件添å å°èµæºæ件ä¸ï¼ç¼è¯çæ¶åå¾å¯è½åºç° qmlcache_loader.o:qmlcache_loader.cpp:(.text+0x32) é误ï¼è¿æ¯å 为qtcé»è®¤ä¼å¼å¯qtquickcompilerï¼ä»¥ä¾¿éè¿é¢å¤çèµæºä¸çææjsæ件ï¼å å¿«æ件å è½½å°Qmlå¼æçé度ï¼ä½æ¯æäºæ¶åæ们并ä¸æ¯ç¨å®å è½½å°qmlè¿è¡ï¼å¯è½æ¯æ¾å¨QtWebEngineä¸ç¨äºäº¤äºï¼æè widgetä¸æ§è¡jså½æ°æ¿å°ç»æãå¯ä»¥å¨qtcç项ç®é ç½®ä¸æ¾å°qt quick compileré项ï¼ä¸ææ¡éæ©ç¦ç¨ãä¹å¯ä»¥å¨proä¸å ä¸è¡ CONFIG -= qtquickcompiler å³å¯ãè¿ä¸ªç¡®åç说æ¯qtçbugï¼å¨5.15.2以ååç»çæ¬ä¸åå¨ã
-
æ°ççQtCreatoré»è®¤çç¼è¯ç®å½è·¯å¾å¨æºç ä¸buildç®å½ï¼ä¹åæ¯å¨æºç å级çbuild-xxxç®å½ï¼ä¸ªäººè¿æ¯å欢ä¹åçæ¹å¼ï¼ææç¼è¯çæç临æ¶æ件å¨æºç å¤åç¬çä¸ä¸ªç®å½ï¼ä¸éè¦çæ¶åç´æ¥å é¤å°±å¥½ï¼æºç ç®å½æ°¸è¿å¹²å¹²ååçãå½ç¶qtcä¹æ¯æä¾äºè®¾ç½®ç®å½çå°æ¹ï¼å¨é¦é项-ãæ建åè¿è¡-ãDefault Build Properties éé¢ç¬¬ä¸è¡ï¼å°ä¹åç ./build/%{Asciify:%{Kit:FileSystemName}-%{BuildConfig:Name}} æ¹æ ../build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name} å³å¯ã
-
å ³äºæµåªä½æ¨ææµå»¶æ¶çå ç¹è¯´æã
- ç»å¸¸çå°ä¸äºæµåªä½ç¸å ³çç¨åºï¼å·ç§°é¶å»¶è¿ï¼ä¸ç¨æçï¼è¿è¯å®å¹çé¼çã
- æé³è§é¢å¼åï¼æä¸ªæ ¸å¿çææ å°±æ¯å®æ¶æ§ï¼ä¹å°±æ¯å»¶è¿å¤å°æ¯«ç§ï¼è¿ä¸ªé®é¢é®çä¹æ¯æå¤çã
- é³è§é¢æ件å ä¹ä¸åå¨å®æ¶æ§é®é¢ï¼åªæé³è§é¢æµææå®æ¶æ§çææ ã
- 延è¿å¤ä¹ è¿ä¸ªæ¶åå°å¾å¤æ¹é¢ï¼ä¹è¦çä½ å¦ä½è®¡ç®ï¼ä»æ¨æµå¼å§è®¡ç®è¿æ¯ä»ææµå¼å§è®¡ç®ã
- å¾å¤å°ä¼ä¼´ä»¬å¹¶ä¸è½æç½ä»ä¹å«å»¶æ¶ï¼è®¤ä¸ºé便ä¸ä¸ªææ¾å¨ææ¾åºæ¥çç»é¢è·åå§æµç»é¢æ¶é´å·®å°±æ¯å»¶æ¶ï¼å ¶å®è¿æ¯å¯¹å»¶æ¶æ大ç误解ã延æ¶ä¸æ¯è¡¨è±¡ï¼å¾å¤äººå¨æµè¯å»¶æ¶æ¶å¾ä¸ä¸ä¸ï¼å¯¹å»¶æ¶æµè¯çä¸ä¸æ§è®¤è¯ä¸è¶³ã
- ä¸é¢æ´ççæ¯zlmä½è åçå ³äºå»¶æ¶çæç« ï¼é常å®æ´èä¸æ代表æ§ã
- éé延æ¶ï¼å¨ééæå头ææ¾å¡ç»é¢æ¶ï¼ç±äºfpsçéå¶åcpuæ§è½ãå åæ·è´é度ç客è§éå¶ï¼ééç»é¢æYUV/RGBçæ°æ®æ¶ä¼æä¸å®ç延æ¶ï¼ä¸è¬å»¶æ¶ä¸ºæ¯«ç§çº§å«ãç±äºä¸è¬ç¼ç å¨å¯¹è¾å ¥æ°æ®æ ¼å¼åå¨éå¶ï¼è¬å¦è¦æ±ç»ä¸è¾å ¥YUV420Pï¼è¿æ ·å¨åRGB->YUV420P转æ¢æ¶ï¼ä¹ä¼æ转æ¢è®¡ç®å»¶æ¶(è¿ä¸ªå¯ä»¥éè¿libyuvåºæ¥éä½)ãæ»è延æ¶ï¼éé延æ¶å¤§æ¦ä¸ºæ¯«ç§çº§å«ï¼å¦æfps为25ï¼é£ä¹ä¸è¬éé延æ¶ä¼æ40毫ç§ï¼1000毫ç§/25fpsï¼ä»¥ä¸ç延æ¶ï¼å¨å åæ·è´åé¢è²è½¬æ¢æ¶ï¼åå¯è½å¢å è¥å¹²æ¯«ç§ç延æ¶ã
- ç¼ç 延æ¶ï¼å¨æåå§ç»é¢è¾å ¥å°ç¼ç å¨æ¶ï¼å¹¶ä¸ä¼ç«å³è¾åºç¼ç åçæ°æ®ï¼ç¹å«æ¯å¨å¼å¯B帧æ¶ï¼ç±äºéè¦åèåé¢çP帧ï¼é£ä¹å»¶æ¶ä¼æ´å¤§ï¼æ以延æ¶ææçæ åµä¸ä¸è¬ä¸å¼å¯B帧ï¼è¿ç§æ åµä¸ç¼ç 延æ¶åºè¯¥æ¯æ¯«ç§çº§å«ï¼ä¸æ¯å¾å¤§ã
- ä¸è¡å»¶æ¶ï¼ç¼ç åçæ°æ®ï¼è¦ç»è¿ä¸å®çåè®®æå æè½åå ¥socketï¼ç¶åä¼ è¾ç»æ¨æµæå¡å¨æææµä»£çæå¡å¨ï¼åè®®æå ä¼æä¸å®çå åæ·è´å计ç®éï¼é£ä¹ä¼å¢å 延æ¶ï¼ä¸è¿è¿ä¸ªå»¶æ¶å¾å°ï¼åºæ¬å¿½ç¥ä¸è®¡ãæ°æ®å¨ä¸ä¼ å°æå¡å¨æ¶ï¼è¿ä¸ªå»¶æ¶å¯å¤§å¯å°ï¼åå³äºç½ç»è´¨éã
- 转æ¢å»¶æ¶ï¼æå¡å¨å¨æ¶å°æ°æ®åï¼è¦è¯»socketç¼åãå议解æã解å¤ç¨ãéæ°æå çæä½ï¼ä¸è¿æ»ä½èè¨ï¼è¿ä¸ªå»¶æ¶æ¯è¾å°ï¼åºæ¬æ²¡ä»ä¹å½±åãææ¶ï¼æå¡å¨ä¸ºäºæé«æ§è½ï¼ä¼éåå并åçæºå¶ï¼ä¹å°±æ¯æ¶å°ä¸å®éçæ°æ®åæä¼ä¸å¹¶è½¬åï¼è¿ä¸ªå»¶æ¶ä¸è¬ä¸ºå ç¾æ¯«ç§ï¼ZLMediaKité»è®¤300毫ç§å·¦å³ï¼ä¸è¿ZLMediaKité»è®¤å ³éå并åï¼ä¹å°±æ¯è¿ä¸ªå»¶æ¶ä¹å¾å°ã
- ä¸è¡å»¶æ¶ï¼æµåªä½å¨æè§é¢æ°æ®è½¬åç»ææ¾å¨æ¶ï¼ä¼åå¨ç½ç»åéï¼è¿ä¸ªå»¶æ¶å¤§å°åå³äºç½ç»è´¨éï¼ZLMediaKitå¨å ³éä½å»¶æ¶æ¨¡å¼æ¶ï¼è¿ä¼å¢å MSG_MOREåå ³éTCP_NODELAY导è´ç延æ¶ï¼ä¸è¿ZLMediaKité»è®¤å¼å¯ä½å»¶æ¶æ¨¡å¼ã
- ææ¾å»¶æ¶ï¼ææ¾å¨å»¶æ¶ä¸»è¦æç½è·¯æ¥æ¶å»¶æ¶ãå议解æ解å¤ç¨å»¶æ¶ã解ç 延æ¶ãç¼å延æ¶ã渲æ延æ¶ç»æï¼è¿äºå»¶æ¶ä¸ç¼å延æ¶æ大ï¼å 为ä¸è¬çææ¾å¨ä¸ºäºä¿è¯å¨ç½ç»æå¨æ åµä¸è§é¢ææ¾çæµç æ§ï¼ä¼ä»¥å¢å 延æ¶ä¸ºä»£ä»·ï¼å¢å ææ¾ç¼åï¼è¿æ ·å¨ç½ç»åå·®æ¶ï¼ä¸è³äºææ¾ç¼å²å¡é¡¿ãèä¸ä¸ºäºé³è§é¢åæ¥ï¼ä¹å¿ 须确ä¿ä¸å®çç¼åéãè¿ç§å»¶æ¶ä¸è¬é½æ¯ç§çº§å«ï¼ä¸è¬5ç§å·¦å³ãæé¨åææ¾çç¥æ¯æ¥æ¶å°æ°æ®åç«å³è§£ç æ¾ç¤ºæ¯å¦rtspè§é¢æµï¼è¿æ ·å¯ä»¥åå°å»¶è¿æå°ã
- ç¼å延æ¶ï¼æµåªä½æå¡å¨ä¸ºäºè½è®©ææ¾å¨ç«å³åºç»é¢ï¼å¾å¾ä¼ç¼åæè¿çä¸ä¸ªI帧ï¼è¿ä¸ªI帧å¾åçææé³è§é¢æ°æ®è¢«ç§°ä½ä¸ºGOPç¼åãå¦æä¸ç¼åGOPï¼é£ä¹ææ¾å¨è¦çä¸ä¸ä¸ªI帧æè½è§£ç æåæä¸è±å±ï¼æ¾ç¶ä¸ºäºæé«ææ¾ä½éªï¼è¿ä¸ªGOPç¼åæ¯ä¸è½å»æçãèä¸è¬GOPçå1~3ç§ï¼é¿å10å ç§ï¼è¿ä¸ªè·éé端ç¼ç å¨è®¾ç½®æå ³ï¼æå¡å¨æ¹åä¸äºãä½æ¯ç±äºä¸è¬çææ¾å¨æ¶å°ç¼ååï¼å¹¶ä¸ä¼ä¸¢å¼è¿å¤çç»é¢æ¥ç¡®ä¿ä½å»¶æ¶ãåµä¸ææ¾å¨è¿å¸ææä¸å®çç¼åæ¥ç¡®ä¿ææ¾çæµç æ§ï¼æ以è¿ä¸ªGOPç¼åå°ä¼å¢å¤§ææ¾å¨ç延æ¶ã
- 综å延æ¶ï¼æå¿«å¯ä»¥åå°200-300msç延è¿ï¼æ¯å¦rtspè§é¢æµï¼å¯¹å®æ¶æ§è¦æ±é«ï¼å¯ä»¥ä¸åç¼ååé³è§é¢åæ¥ï¼æ¶å°å°±ç«å³è§£ç ææ¾ãhlsä¸è¬æå¿«å¯ä»¥åå°5s延è¿ï¼flvä¸è¬å¯ä»¥åå°3s延è¿ã
- æç»æ»ç»ï¼ç»¼åèèå®æ¶æ§ä»¥åæ¯æçé³è§é¢æ ¼å¼ï¼ä¸ªäººå»ºè®®ï¼æ¨æµç¨rtspæ¨æµï¼æ¯æçé³è§é¢æ ¼å¼æå好ï¼æ¯å¦æ¯æ265ï¼ï¼ææµå¨webä¸ä¸ªäººæ¨èç¨ws-flvæ ¼å¼ææµï¼æ¯æçæ ¼å¼å¤ï¼æ²¡æ6个åæºçéå¶ï¼ï¼ææµå¨å¯æ§è¡æ件ä¸ç¨rtspï¼æ ¼å¼å¤èä¸å®æ¶æ§æ好ï¼å¯ä»¥æå¿«é度解ç ææ¾ï¼ï¼å¨ç½é¡µä¸è½ç¶webrtcå®æ¶æ§æ好ï¼ä½æ¯ä¸æ¯æ265ï¼è¿ä¸ªå°±é¾æã
- Qtèªå¸¦ç对è¯æ¡çæé®è®¾ç½®ä¸æã
//ä¿¡æ¯æ¡è®¾ç½®ä¸æ
QMessageBox dialog(QMessageBox::Question, "询é®", text);
dialog.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
dialog.button(QMessageBox::Yes)->setText("ç¡® å®");
dialog.button(QMessageBox::No)->setText("å æ¶");
return dialog.exec();
//è¾å
¥æ¡è®¾ç½®ä¸æ
QInputDialog dialog;
dialog.setOkButtonText("ç¡®å®");
dialog.setCancelButtonText("åæ¶");
return dialog.exec();
//对è¯æ¡è®¾ç½®ä¸æ
QFileDialog dialog;
dialog.setOption(QFileDialog::DontUseNativeDialog, true);
QLabel *lookinLabel = dialog.findChild<QLabel*>("lookInLabel");
lookinLabel->setText("æ件ç®å½ï¼");
- ææ¶åéè¦å¯¹æ ç¶èç¹è¿è¡æç´¢è¿æ»¤æ¾ç¤ºï¼å¹é å°çèç¹æ¾ç¤ºï¼æ²¡æå¹é çéèãè¿ä¸ªåè½å¾å¤å°æ¹ç¨ï¼å°è£ äºä¸ä¸ªéæå½æ°ç´æ¥è°ç¨ã
//è°ç¨æ¹æ³ QtHelper::search(ui->treeWidget, "æµè¯", 5);
void QtHelper::search(QTreeWidget *treeWidget, const QString &key, int level)
{
//æ¾å°ææå¹é
çèç¹
QList<QTreeWidgetItem *> items = treeWidget->findItems(key, Qt::MatchContains | Qt::MatchRecursive);
//å°å¹é
å°çèç¹å å
¥éå/该èç¹çç¶èç¹ä¹ç¸å½äºå¹é
/ä¸ç¶ç¶èç¹éèåèç¹ä¹ä¼è·çéè
QList<QTreeWidgetItem *> itemAll;
foreach (QTreeWidgetItem *item, items) {
//å½åèç¹çææç¶èç¹ä¹æ·»å è¿å»/å 次循ç¯ç¸å½äºå 个å±çº§
for (int i = 0; i < level; ++i) {
//å»éæ·»å
if (!itemAll.contains(item)) {
itemAll << item;
}
//为空表示没æç¶èç¹åè·³åºå¾ªç¯
item = item->parent();
if (!item) {
break;
}
}
}
//éåææèç¹/å¹é
çèç¹æ¾ç¤ºå¦åéè
QTreeWidgetItemIterator it(treeWidget);
while (*it) {
(*it)->setHidden(!itemAll.contains(*it));
++it;
}
}
2 å级å°Qt6
00ï¼ç´è§æ»ç»
- å¢å äºå¾å¤è½®åï¼åæ¶åæ模åæåçä¹æ´ç»è´ï¼ä¼°è®¡ä¸ºäºæ¹ä¾¿æå±ä¸ªç®¡çã
- æä¸äºè¿åº¦å°è£ çä¸è¥¿ç§»é¤äºï¼æ¯å¦åæ ·çåè½æå¤ä¸ªå½æ°ï¼ï¼ä¿è¯äºåªæä¸ä¸ªå½æ°æ§è¡è¯¥åè½ã
- æä¸äºQt5ä¸å ¼å®¹Qt4çæ¹æ³åºå¼äºï¼å¿ é¡»ç¨Qt5ä¸å¯¹åºçæ°çå½æ°ã
- è·éæ¶ä»£èæ¥ï¼å¢å äºä¸å°æ°ç¹æ§ä»¥æ»¡è¶³æ¥çå¢é¿ç客æ·éæ±ã
- 对æäºæ¨¡ååç±»ååå¤çè¿è¡äºé©å½æ§çéåï¼è¿è¡æçæé«ä¸å°ã
- æåæ°ç±»åçååï¼æ¯å¦ long * å° qintptr * çï¼æ´å éåºåç»çæå±ä»¥ååæ¶å¯¹32 64ä½ä¸åç³»ç»çå ¼å®¹ã
- æºç ä¸çdoubleæ°æ®ç±»åå ¨é¨æ¢æäºqrealï¼åQtå é¨æ°æ®ç±»åé«åº¦ä¸è´åç»ä¸ã
- ææµè¯çé½æ¯QWidgeté¨åï¼quické¨å没ææµè¯ï¼ä¼°è®¡quické¨åæ´æ°å¯è½ä¼æ´å¤ã
- 强ç建议ææ¶ä¸è¦ç¨Qt6.0å°Qt6.2ä¹é´ççæ¬ï¼ä¸äºæ¨¡åè¿ç¼ºå¤±ï¼ç¸å¯¹æ¥è¯´BUGä¹æ¯è¾å¤ï¼æ¨è6.2.2çæ¬å¼å§æ£å¼è¿ç§»ã
01ï¼01-10
-
ä¸è½æ¹æ³ï¼å®è£ 5.15çæ¬ï¼å®ä½å°æ¥éçå½æ°ï¼åæ¢å°æºç 头æ件ï¼å¯ä»¥çå°å¯¹åºæ示åæ · QT_DEPRECATED_X("Use sizeInBytes") åæ°å½æ°ãæç §è¿ä¸ªæ示类修æ¹å°±æ²¡éï¼ä¸äºå½æ°æ¯ä»Qt5.7 5.9 5.10ççæ¬æ°å¢å çï¼å¯è½ä½ ç项ç®è¿ç¨çQt4çæ¹æ³ï¼ä½æ¯Qt6以åé½å ¼å®¹è¿äºæ§æ¹æ³ï¼å°äºQt6就彻åºéè¦ç¨æ°æ¹æ³äºãPSï¼å¦ææ¬èº«å°±æ¯Qt6æ°å¢çåè½å½æ°åæ¤æ¹æ³æ æ
-
Qt6对coreè¿ä¸ªæ ¸å¿ç±»è¿è¡äºæåï¼å¤åºæ¥core5compatï¼å æ¤ä½ éè¦å¨proå¢å 对åºç模åå·²ç»ä»£ç ä¸å¼å ¥å¯¹åºç头æ件ã
//proæ件å¼å
¥æ¨¡å
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
//代ç ä¸å¼å
¥å¤´æ件
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QtWidgets>
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
#include <QtCore5Compat>
#endif
- é»è®¤Qt6å¼å¯äºé«åå±æ¯æï¼çé¢ä¼åå¾å¾å¤§ï¼çè³åä½åèï¼å¾å¤äººä¼ä¸ä¹ æ¯ï¼å 为è¿ç§æ¨¡å¼å¦æç¨åºå¾å¤åæ 计ç®æ²¡æéç¨devicePixelRatioè¿è¡è¿ç®çè¯ï¼100%ä¼åºç°å¥å¥æªæªçé®é¢ï¼å 为åæ ä¸åç¡®äºãè¦åæ¶è¿ç§ææå¯ä»¥è®¾ç½®é«åå±ç¼©æ¾å åã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
#endif
-
åæçéæºæ°å½æ°æ示ç¨QRandomGeneratoræ¿ä»£ï¼ä¸ºäºå ¼å®¹ææqtçæ¬ï¼æ¹å¨æå°çåæ³æ¯ç´æ¥ç¨c++ä¸çéæºæ°ï¼æ¯å¦qsrandå½æ°æ¢æsrandï¼qrandå½æ°æ¢ærandï¼æ¥çè¿æºä»£ç ï¼å ¶å®å°è£ çå°±æ¯c++ä¸çéæºæ°ï¼å¾å¤ç±»ä¼¼çå°è£ æ¯å¦qSinå°è£ çsinã
-
QColorç light æ¹æ lighter ï¼dark æ¹æ darkerï¼å ¶å® lighterãdarker è¿ä¸¤ä¸ªæ¹æ³ä»¥åä¸ç´æã
-
QFontMetricsF ä¸ç fm.width æ¢æ fm.horizontalAdvance ï¼ä»5.11å¼å§ç¨æ°å½æ°ã
-
QPaletteè°è²æ¿æ举å¼ï¼Foreground = WindowText, Background = Windowï¼å ¶ä¸ Foreground å Background 没æäºï¼è¦ç¨ WindowText å Window æ¿ä»£ï¼ä»¥åå°±æã类似çè¿æ setTextColor æ¹æäº setForeground ã
-
QWheelEventç delta() æ¹æ angleDelta().y()ï¼pos() æ¹æ position() ã
-
svg模åæååºæ¥äºsvgwidgetsï¼å¦æç¨å°äºè¯¥æ¨¡ååéè¦å¨proå¢å QT += svgwidgets ï¼åçopengl模åæååºæ¥äºopenglwidgetsã
-
qlayoutä¸ç margin() å½æ°æ¢æ contentsMargins().left()ï¼æ¥çæºç å¾ç¥ä»¥åç margin() è¿åçå°±æ¯ contentsMargins().left()ï¼å¨å个æ°å¼ä¸æ ·çæ¶åï¼é»è®¤å个æ°å¼å°±æ¯ä¸æ ·ã类似çè¿æsetMargin移é¤äºï¼ç»ç»ç¨setContentsMarginsã
02ï¼11-20
-
ä¹å QChar c = 0xf105 å ¨é¨è¦æ¹æ强å¶è½¬æ¢ QChar c = (QChar)0xf105ï¼ä¸åæéå¼è½¬æ¢ï¼ä¸ç¶ç¼è¯æ¥éæ示error: conversion from 'int' to 'QChar' is ambiguous ã
-
qSortçä¸äºå½æ°ç¨åc++ç std::sort ã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
std::sort(ipv4s.begin(), ipv4s.end());
#else
qSort(ipv4s);
#endif
-
Qt::WA_NoBackground æ¹æ Qt::WA_OpaquePaintEvent ã
-
QMatrix ç±»åºå¼äºæ²¡æäºï¼æ¢æ QTransform ï¼å½æ°åè½åºæ¬ä¸è´ï¼QTransform ç±»å¨Qt4å°±ä¸ç´æã
-
QTime 计æ¶å»æäºï¼éè¦æ¹æ QElapsedTimer ï¼QElapsedTimer ç±»å¨Qt4å°±ä¸ç´æã
-
QApplication::desktop()åºå¼äºï¼ æ¢æäº QApplication::primaryScreen()ã
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
#include "qscreen.h"
#define deskGeometry qApp->primaryScreen()->geometry()
#define deskGeometry2 qApp->primaryScreen()->availableGeometry()
#else
#include "qdesktopwidget.h"
#define deskGeometry qApp->desktop()->geometry()
#define deskGeometry2 qApp->desktop()->availableGeometry()
#endif
- è·åå½åå±å¹ç´¢å¼ä»¥å尺寸éè¦åå«å¤çã
//è·åå½åå±å¹ç´¢å¼
int QtHelper::getScreenIndex()
{
//éè¦å¯¹å¤ä¸ªå±å¹è¿è¡å¤ç
int screenIndex = 0;
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
int screenCount = qApp->screens().count();
#else
int screenCount = qApp->desktop()->screenCount();
#endif
if (screenCount > 1) {
//æ¾å°å½åé¼ æ æå¨å±å¹
QPoint pos = QCursor::pos();
for (int i = 0; i < screenCount; ++i) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
if (qApp->screens().at(i)->geometry().contains(pos)) {
#else
if (qApp->desktop()->screenGeometry(i).contains(pos)) {
#endif
screenIndex = i;
break;
}
}
}
return screenIndex;
}
//è·åå½åå±å¹å°ºå¯¸åºå
QRect QtHelper::getScreenRect(bool available)
{
QRect rect;
int screenIndex = QtHelper::getScreenIndex();
if (available) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
rect = qApp->screens().at(screenIndex)->availableGeometry();
#else
rect = qApp->desktop()->availableGeometry(screenIndex);
#endif
} else {
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
rect = qApp->screens().at(screenIndex)->geometry();
#else
rect = qApp->desktop()->screenGeometry(screenIndex);
#endif
}
return rect;
}
- QRegExp类移å°äºcore5compat模åï¼éè¦ä¸»å¨å¼å ¥å¤´æ件 #include "QRegExp"ã
//设置éå¶åªè½è¾å
¥æ°å+å°æ°ä½
QString pattern = "^-?[0-9]+([.]{1}[0-9]+){0,1}$";
//设置IPå°åæ ¡éªè¿æ»¤
QString pattern = "(2[0-5]{2}|2[0-4][0-9]|1?[0-9]{1,2})";
//ç¡®åç说 QRegularExpression QRegularExpressionValidator ä»5.0 5.1å¼å§å°±æ
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QRegularExpression regExp(pattern);
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
#else
QRegExp regExp(pattern);
QRegExpValidator *validator = new QRegExpValidator(regExp, this);
#endif
lineEdit->setValidator(validator);
- QWheelEventæé åæ°å对åºç计ç®æ¹ä½å½æ°åäºã
//模æé¼ æ æ»è½®
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
QWheelEvent wheelEvent(QPoint(0, 0), -scal, Qt::LeftButton, Qt::NoModifier);
#else
QWheelEvent wheelEvent(QPointF(0, 0), QPointF(0, 0), QPoint(0, 0), QPoint(0, -scal), Qt::LeftButton, Qt::NoModifier, Qt::ScrollBegin, false);
#endif
QApplication::sendEvent(widget, &wheelEvent);
//é¼ æ æ»è½®ç´æ¥ä¿®æ¹å¼
QWheelEvent *whellEvent = (QWheelEvent *)event;
//æ»å¨çè§åº¦,*8å°±æ¯é¼ æ æ»å¨çè·ç¦»
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
int degrees = whellEvent->delta() / 8;
#else
int degrees = whellEvent->angleDelta().x() / 8;
#endif
//æ»å¨çæ¥æ°,*15å°±æ¯é¼ æ æ»å¨çè§åº¦
int steps = degrees / 15;
- qVariantValue æ¹æ qvariant_cast ï¼qVariantSetValue(v, value) æ¹æäº v.setValue(val)ãç¸å½äºéåå°æåå§çæ¹æ³ï¼æ¥çqVariantValueæºç å°è£ çå°±æ¯qvariant_castã
03ï¼21-30
-
QStyleOptionçinitæ¹æäºinitFromã
-
QVariant::Type æ¢æäº QMetaType::Type ï¼æ¬èº«ä»¥åç QVariant::Type å°è£ çå°±æ¯ QMetaType::Type ã
-
QStyleOptionViewItemV2 V3 V4 ä¹ç±»çå ¨é¨æ²¡æäºï¼ææ¶å¯ä»¥ç¨ QStyleOptionViewItem æ¿ä»£ã
-
QFontç resolve çä¸ä¸ªéè½½å½æ°æ¢æäº resolveMaskã
-
QSettingsç setIniCodec æ¹æ³ç§»é¤äºï¼é»è®¤å°±æ¯utf8ï¼ä¸éè¦è®¾ç½®ã
-
qcombobox ç activated(QString) å currentIndexChanged(QString) ä¿¡å·å é¤äºï¼ç¨intç´¢å¼åæ°çé£ä¸ªï¼ç¶åèªå·±éè¿ç´¢å¼è·åå¼ã个人è§å¾è¿ä¸ªæ²¡å¿ è¦å é¤ã
-
qtscript模åå½»åºæ²¡æäºï¼å°½ç®¡ä»Qt5æ¶ä»£çåæçæ¬å°±æ示为åºå¼æ¨¡åï¼ä¸ç´åæå°Qt6ææ£å¼åºå¼ï¼åç§jsonæ°æ®è§£æå ¨é¨æ¢æqjson类解æã
-
QByteArray ç append indexOf lastIndexOf çä¼å¤æ¹æ³çQStringåæ°éè½½å½æ°åºå¼äºï¼è¦ç´æ¥ä¼ QByteArrayï¼å°±å¨åæ¥åæ°åºç¡ä¸å ä¸ .toUtf8() ãæ¥çæºç ä¹çå¾å°ä»¥åçQStringåæ°ä¹æ¯è½¬æ.toUtf8()åå»æ¯è¾ã
-
QDateTimeçæ¶é´è½¬æ¢å½æ° toTime_t + setTime_t ååæ¹äºï¼å¯¹åºæ¹æäº toSecsSinceEpoch + setSecsSinceEpoch ï¼è¿ä¸¤ä¸ªæ¹æ³å¨Qt5.8æ¶åæ°å¢å çã
-
QLabelç pixmap å½æ°ä¹åæ¯æé *pixmap() ç°å¨æ¢æäºå¼ç¨ pixmap()ã
04ï¼31-40
-
QTableWidgetç sortByColumn æ¹æ³ç§»é¤äºé»è®¤ååºçæ¹æ³ï¼å¿ é¡»è¦å¡«å ¥ç¬¬äºä¸ªåæ°è¡¨ç¤ºååºè¿æ¯éåºã
-
qtnetwork模åä¸ï¼TCP/UDPç¸å ³çsocketï¼çé误信å·erroræ¢æäºerrorOccurredï¼å°±æ¹äºä¸ªååï¼æ³¨æwebsocketé£åå± ç¶æ²¡ç»ä¸æ¹è¿æ¥ä¾ç¶æ¯å«errorã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(udpSocket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
connect(tcpSocket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(error()));
#else
connect(udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
#endif
//ç¹å«æ³¨æwebsocketä¸ä¾ç¶è¿æ¯ç¨error
connect(webSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error()));
-
XmlPatterns模åæ¨æäºï¼å ¨é¨ç¨xml模åéæ°è§£æã
-
nativeEventçåæ°ç±»ååäºã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
#else
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#endif
- QButtonGroupçbuttonClickedä¿¡å·ä¸intåæ°çå½æ°å ¨é¨æ¹ååå«idClickedã
QButtonGroup *btnGroup = new QButtonGroup(this);
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(btnGroup, SIGNAL(idClicked(int)), ui->xstackWidget, SLOT(setCurrentIndex(int)));
#else
connect(btnGroup, SIGNAL(buttonClicked(int)), ui->xstackWidget, SLOT(setCurrentIndex(int)));
#endif
- QWebEngineSettingsä¹åæ¯QWebEngineSettings::defaultSettings();ç°å¨æ¹æäºQWebEngineProfile::defaultProfile()->settings();éè¿æ¥çä¹åçæºç å¾ç¥QWebEngineSettings::defaultSettings();å°è£ çå°±æ¯QWebEngineProfile::defaultProfile()->settings();å 为Qt6å»é¤äºNå¤è¿åº¦å°è£ çå½æ°ã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
QWebEngineSettings *webSetting = QWebEngineProfile::defaultProfile()->settings();
#else
QWebEngineSettings *webSetting = QWebEngineSettings::defaultSettings();
#endif
- Qt6å°enterEventçåæ°QEventæ¹æäºQEnterEventä¹ä¸æ个æå¼ãè¿ç§æ¹åç¼è¯ä¹ä¸ä¼æ示çã
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
void enterEvent(QEnterEvent *);
#else
void enterEvent(QEvent *);
#endif
//åé¢ç»è¿JasonWong大佬çæç¹ï¼ä»ç¶ç±»éæ°å®ç°çvirtual修饰çå½æ°ï¼å»ºè®®é½å ä¸overrideå
³é®åã
//è¿æ ·çè¯ä¸æ¦ç¶ç±»çå½æ°æè
åæ°åäºåä¼æ示ç¼è¯æ¥éï¼èä¸æ¯ç¼è¯éè¿ä½æ¯è¿è¡ä¸æ£å¸¸ä¼ä¸è¸æµé¼è«ç¶ï¼ä»èæé
æ£ç»Qtã
//ä¸é¢æ¯ç¶ç±»å½æ°
virtual void enterEvent(QEvent *event);
//å类建议å ä¸override
void enterEvent(QEvent *event) override;
-
Qt6ä¸å¤ä¸ªç±»è¿è¡äºå并ï¼æ¯å¦ç°å¨QVectorå°±æäºQListçå«åï¼æå³çè¿ä¸¤ä¸ªç±»æ¯åä¸ä¸ªç±»æ²¡æä»»ä½åºå«ï¼å¯è½Qtå é¨å¯¹ä¸¤ç§çä¼ç¹é½éä¸å¨ä¸èµ·ï¼å¹¶å°½ééåç®æ³æè å ¶ä»å¤çè§é¿ç¼ºç¹ãåçQStringListç°å¨ä¹æäº QList<QString> çå«åï¼æ¯åä¸ä¸ªç±»ï¼æ²¡æåç¬çç±»ã
-
å¨Qt4æ¶ä»£é»è®¤QWidgetæé å½æ°ç¶ç±»æ¯0ï¼å°äºQt5åæäºQ_NULLPTRï¼å°äºQt6å± ç¶ç¨çæ¯é»è®¤çc++æ åä¸çnullptrèä¸æ¯Qtèªå®ä¹å®ä¹çQ_NULLPTRï¼åæ ·çè¿æQ_DECL_OVERRIDEæ¢æäºç¨overrideçï¼ï¼å¯è½æ¯ä¸ºäºå½»åºæå¼åå²å 袱æ¥æ±æªæ¥ã
//ä¸é¢ä¾æ¬¡æ¯Qt4/5/6çåæ³
MainWindow(QWidget *parent = 0);
MainWindow(QWidget *parent = Q_NULLPTR);
MainWindow(QWidget *parent = nullptr);
//æ¥é
Qtæºç æ¥çQ_NULLPTRåæ¥æ¯æ ¹æ®ç¼è¯å¨å®ä¹æ¥éæ©
#ifdef Q_COMPILER_NULLPTR
# define Q_NULLPTR nullptr
#else
# define Q_NULLPTR NULL
#endif
//Qté«çæ¬å
¼å®¹ä½çæ¬åæ³æ¯å¦Qt5/6é½æ¯æ *parent = 0 è¿ç§åæ³ã
- 对äºå§æçè¿åº¦æ¡æ ·å¼QStyleOptionProgressBarç±»çå±æ§ï¼å¨Qt4çæ¶åä¸è½è®¾ç½®æ¨ªåè¿æ¯åç´æ ·å¼ï¼é»è®¤æ¨ªåæ ·å¼ï¼è¦è®¾ç½®orientationéè¦ç¨å¦å¤çQStyleOptionProgressBarV2ãä»Qt5å¼å§æ°å¢äºorientationåbottomToTopå±æ§è®¾ç½®ãå¨Qt6çæ¶åå½»åºç§»é¤äºorientationå±æ§ï¼åªæbottomToTopå±æ§ï¼èä¸é»è®¤è¿åº¦æ¯åç´çï¼å¾æèï¼ç论ä¸é»è®¤åºè¯¥æ¯æ¨ªåçæ对ï¼ç»å¤§é¨åè¿åº¦æ¡åºæ¯é½æ¯æ¨ªåçãè¿ä¸ªæ¶åæä¹åå¢ï¼åæ¥ç°å¨çå¤çé»è¾æ¹äºï¼é»è®¤åç´çï¼å¦æè¦è®¾ç½®æ¨ªåçç´æ¥è®¾ç½® styleOption.state |= QStyle::State_Horizontal è¿ç§æ¹å¼è®¾ç½®æè¡ï¼èQt6以åé»è®¤æ¹åæ¯éè¿ orientation å¼åå¾ï¼è¿ä¸ªState_Horizontalä»Qt4å°±ä¸ç´æï¼Qt6以åè¦ä¸»å¨è®¾ç½®ä¸ææ¯æ¨ªåçå°±æ¯ã
05ï¼41-50
-
Qt6.2çæ¬å¼å§å¢å äºå¯¹å¤åªä½æ¨¡åçæ¯æï¼ä½æ¯å¨mingwç¼è¯å¨ä¸è¿æ¯æé®é¢ï¼ç´å°6.2.2æä¿®å¤è¿ä¸ªé®é¢ï¼å®ç½è§£éæ¯å 为mingwç¼è¯å¨çæ¬ä¸æ¯æï¼å°6.2.2éç¨äºæ°çmingw900_64ï¼è¿ä¸ªç¼è¯å¨çæ¬ææ¯æãæ以ç论ä¸æ¨èä»6.2.2å¼å§ä½¿ç¨æ°çQt6ã
-
QTextStreamä¸çsetCodecæ¹æ³æ¹æäºsetEncodingï¼åæ°åäºï¼åè½æ´å¼ºå¤§ã
QTextStream stream(&file);
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
stream.setCodec("utf-8");
stream.setCodec("gbk");
#else
stream.setEncoding(QStringConverter::Utf8);
stream.setEncoding(QStringConverter::System);
#endif
- QModelIndexçæ¥æ¾åèç¹childå½æ°å»æäºï¼ä½æ¯æ¥æ¾ç¶èç¹parentå½æ°ä¿çï¼æ¥é 代ç å¾ç¥ä¹åçchildå½æ°å°±æ¯å°è£ çmodel->index(row, column, QModelIndex)å½æ°ã
//ä¸é¢ä¸¤ä¸ªå½æ°çä»· å¦æè¦å
¼å®¹Qt456åç¨ä¸é¢è¿ä¸ªæ¹æ³
QModelIndex index = indexParent.child(i, 0);
QModelIndex index = model->index(i, 0, indexParent);
//ä¸é¢ä¸¤ä¸ªå½æ°çä»· å¦æè¦å
¼å®¹Qt456åç¨ä¸é¢è¿ä¸ªæ¹æ³
QModelIndex indexChild = index.child(i, 0);
QModelIndex indexChild = model->index(i, 0, index);
- ä¹åQPixmapç±»ä¸çéæå½æ°grabWindowågrabWidgetå½»åºåºå¼äºï¼æ¹æäºç¨QApplication::primaryScreen()->grabWindowï¼å ¶å®è¿ä¸ªä»Qt5å¼å§å°±å»ºè®®ç¨è¿ä¸ªã
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
QPixmap pixmap = QApplication::primaryScreen()->grabWindow(widget->winId());
#else
QPixmap pixmap = QPixmap::grabWidget(widget->winId());
#endif
- QProcessä¸çstartæ¹æ³ä»¥åç´æ¥æ¯æä¼ å ¥å®æ´çå½ä»¤ï¼å°äºQt6ä¸¥æ ¼è¦æ±å¿ é¡»æååé¢çåæ°ã
//Qt6以åæ¯ææ§è¡å®æ´å½ä»¤
QProcess p;
p.start("wmic cpu get Name");
//Qt6éè¦æ¹æä¸é¢çæ¹æ³ï¼æ¤æ¹æ³ä¹å
¼å®¹Qt4ã5ã6
p.start("wmic", QStringList() << "cpu" << "get" << "Name");
- å¨qssä¸å¯¹å±æ§çæ举å¼åæ³å°äºQt6æ¢æäºæ°å¼è¡¨ç¤ºï¼éè¦ç¿»é æ举å¼çå®ä¹æ¾å°å¯¹åºçå¼ï¼ï¼è¿ä¸ªæ¹å¨æºå¤§ï¼åè®°éè¦åæ¢è¿æ¥ï¼èä¸è¿ç§åæ³ä¸å ¼å®¹Qt5ã
//Qt4/5 éè¿æ ·å¼è¡¨è®¾ç½®æ ç¾å³ä¸è§å¯¹é½
ui->label->setStyleSheet("qproperty-alignment:AlignRight;");
//Qt4/5 éè¿æ ·å¼è¡¨è®¾ç½®æ ç¾å±
ä¸å¯¹é½
ui->label->setStyleSheet("qproperty-alignment:AlignHCenter|AlignVCenter;");
//Qt6 éè¿æ ·å¼è¡¨è®¾ç½®æ ç¾å³ä¸è§å¯¹é½ ç¿»é
AlignRight çæ举å¼=2
ui->label->setStyleSheet("qproperty-alignment:2;");
//Qt6 éè¿æ ·å¼è¡¨è®¾ç½®æ ç¾å±
ä¸å¯¹é½ ç¿»é
AlignHCenter|AlignVCenter çæ举å¼=0x04|0x80=0x84=132
ui->label->setStyleSheet("qproperty-alignment:132;");
- Qt6ä¸å¤åªä½æ¨¡åçç±»åäºå·¨å¤§è°æ´æ¹å¨ï¼æäºæ¯ç±»åçååï¼æ¯å¦é³é¢è¾åºï¼ä¹å«ææ¾ï¼ä¹åæ¯ QAudioOutput ç°å¨æ¯ QAudioSink ï¼é³é¢è¾å ¥ï¼ä¹å«å½é³ï¼ä¹åæ¯ QAudioInput ç°å¨æ¯ QAudioSource ï¼é»è®¤é³é¢è¾å ¥è¾åºè®¾å¤éåä¹åæ¯ QAudioDeviceInfo::defaultInputDevice()ãQAudioDeviceInfo::defaultOutputDevice()ï¼ç°å¨æ¯ QMediaDevices::defaultAudioInput()ãQMediaDevices::defaultAudioOutput()ãæè§è¿ä¸ªååæ¹ç没æ以åè´´åã
#if (QT_VERSION >= QT_VERSION_CHECK(6,2,0))
#define AudioInput QAudioSource
#define AudioOutput QAudioSink
#else
#define AudioInput QAudioInput
#define AudioOutput QAudioOutput
#endif
//使ç¨çæ¶ååªéè¦newå°±è¡
AudioInput *input = new AudioInput(format, this);
#if (QT_VERSION >= QT_VERSION_CHECK(6,2,0))
#define QAudioInput QAudioSource
#define QAudioOutput QAudioSink
#endif
//使ç¨çæ¶ååªéè¦newå°±è¡
QAudioInput *input = new QAudioInput(format, this);
-
Qt6å¼å§é»è®¤ç¨cmakeï¼æ以ç°å¨æ°ççqtcreatorå¨æ°å»ºé¡¹ç®çæ¶åé»è®¤éæ©çå°±æ¯cmakeï¼å¾å¤åå¦è é¦æ¬¡ç¨çæ¶åä¼åç°ï¼æä¹çªç¶ä¹é´çæç项ç®ï¼ç»æé½ä¸ä¸æ ·ï¼çªç¶ä¹é´æµé¼äºï¼æ以è¦å¨æ°å»ºé¡¹ç®çè¿ç¨ä¸éæ©qmakeï¼éæ©ä¸æ¬¡ä»¥åå°±é»è®¤qmakeäºã
-
Qt6.4å¼å§å¯¹åºç±»QString/QByteArrayçcountå½æ°åºå¼äºï¼æ¹ç¨size/lengthå½æ°ï¼ä¼°è®¡å¯è½æè¿°æ´åç¡®å§ã
-
Qt6.4.1æ°å¢äºNå¤BUGï¼å¼ºçä¸å»ºè®®ä½¿ç¨ï¼æ¯å¦QAudioSinkææ¾å£°é³æ²¡æå£°é³ https://bugreports.qt.io/browse/QTBUG-108383ï¼DPI缩æ¾ä¸¥éåå½¢ https://bugreports.qt.io/browse/QTBUG-108593ãè¿äºBUGå¨6.4.0/6.5.0æ¯ä¸åå¨çï¼KPI害æ»äººåã
-
Qt6.5çæ¬å¼å§åæ¶äºQVariantçé»è®¤æé å½æ°ï¼ä¹åreturn QVariant() ç°å¨å¿ é¡»æ¹æ QVariant(QVariant::Invalid) æä¸ä¼æè¦åæ示ãéè¿æå°å¼åç°QVariant()æ¬èº«å°±=QVariant(QVariant::Invalid)ï¼æ以ç»ä¸åæQVariant(QVariant::Invalid)å ¼å®¹Qt456ã
3 å®åå¼åç»éª
01ï¼01-05
- proä¸å¼å ¥å®åæå±æ¨¡å QT += androidextras ã
- proä¸æå®å®åæå ç®å½ ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android æå®å¼å ¥å®åç¹å®ç®å½æ¯å¦ç¨åºå¾æ ãåéãé¢è²ãjava代ç æ件ãjaråºæ件çã
- AndroidManifest.xml æ¯ä¸ªç¨åºå¯ä¸çä¸ä¸ªå ¨å±é ç½®æ件ï¼éé¢xmlæ ¼å¼çæ°æ®ï¼æ ææ¯æçå®åçæ¬ãå¾æ ä½ç½®ã横å±ç«å±ãæéçãè¿ä¸ªæ件æ¯æå ³é®çï¼å¦æ没æè¿ä¸ªæ件åQtä¼é»è®¤çæä¸ä¸ªã
- android/res/drawable-hdpi drawable-xxxhdpi çç®å½ä¸åæ¾çæ¯åºç¨ç¨åºå¾æ ã
- android/res/layout ç®å½ä¸åæ¾çå¸å±æ件ã
- android/res/values/libs.xml åå¨çä¸äºåéå¼ã
- android/libs ç®å½ä¸åæ¾çjaråºæ件ã
- android/src ç®å½ä¸åæ¾çjava代ç æ件ï¼å¯ä»¥æ¯æ ¹æ®å å建ç«çä¸å±å±åç®å½ï¼ä¹å¯ä»¥ç´æ¥å¨srcç®å½ä¸ã
- å ¶ä»ç®å½èªè¡æç´¢å®åç®å½è§èã
- åé¢ç说æç»ä¸ç¨çandroidç®å½ä¸¾ä¾ï¼å ¶å®ä½ å¯ä»¥æ¹æä»»æç®å½ï¼æ¯å¦ä½ ç代ç ç®å½ä¸æ¯xxooåæ¾çå®åç¸å ³çæå æ件ï¼ä½ å°±åæ ANDROID_PACKAGE_SOURCE_DIR = $$PWD/xxoo ã
- javaç±»åå¿ é¡»åæ件åå®å ¨ä¸è´ï¼åºå大å°åã
- javaç±»å¿ é¡»å¨android/srcç®å½ä¸ä¸ç¶ä¸ä¼æå å°apkæ件ï¼å¯ä»¥æ¯åç®å½æ¯å¦ android/src/com/qt ã
- Qt代ç ä¸çQAndroidJniObjectæå®ä¼ å ¥çjavaå åï¼å¿ é¡»ä¸¥æ ¼åjavaæ件packageå®å ¨ä¸è´ï¼ä¸ç¶ç¨åºæ§è¡å°æ¤å¤ä¼å 为æ¾ä¸å°èå´©æºã
- android/scr/MainActivity.java é¡¶é¨ æ²¡æ package å代ç ä¸å¿ é¡»æ¯ QAndroidJniObject javaClass("MainActivity");
- android/scr/MainActivity.java é¡¶é¨ package com.qandroid; å代ç ä¸å¿ é¡»æ¯ QAndroidJniObject javaClass("com/qandroid/MainActivity");
- android/scr/com/example/MainActivity.java é¡¶é¨ package com.qandroid; å代ç ä¸å¿ é¡»æ¯ QAndroidJniObject javaClass("com/qandroid/MainActivity");
- android/scr/com/example/MainActivity.java é¡¶é¨ package com.example.qandroid; å代ç ä¸å¿ é¡»æ¯ QAndroidJniObject javaClass("com/qandroid/example/MainActivity");
- æ»ä¹è¿ä¸ªå åæ¯å代ç ä¸çpackageåé¢ä¸æ®µå»åï¼èä¸æ¯ç®å½è·¯å¾ã为äºç»ä¸ç®¡çæ¹ä¾¿æ¥æ¾æ件ï¼å»ºè®®å ååç®å½è·¯å¾ä¸è´ã
02ï¼06-10
- Qtåªè½å¹²Qtå é¨ç±»çäºæ ï¼åä¸äºç®åçUI交äºè¿æ¯é常æ¹ä¾¿ï¼å¦ææ¶åå°åºå±æä½ï¼è¿æ¯éè¦çæjavaä¼å¦è添翼ï¼ä¸è¬çåæ³å°±æ¯å好javaæ件è°è¯å¥½ï¼æä¾éææ¹æ³ç»Qtè°ç¨ï¼è¿æ ·éè¿QAndroidJniObjectè¿ä¸ªä¸è½è¶æ°´å¯ä»¥åå°Qtç¨åºè°ç¨javaä¸çå½æ°å¹¶æ¿å°æ§è¡ç»æï¼ä¹å¯ä»¥æ¥æ¶javaä¸çå½æ°ã
- proä¸éè¿ OTHER_FILES += android/AndroidManifest.xml OTHER_FILES += android/src/JniMessenger.java å¼å ¥æä»¶å ¶å®å¯¹æ´ä¸ªç¨åºçç¼è¯æå 没æä»»ä½å½±åï¼å°±æ¯ä¸ºäºæ¹ä¾¿å¨QtCreatorä¸æ¥çåç¼è¾ã
- å¨Qtä¸ä¸å®åçjavaæ件交äºé½æ¯ç¨ä¸è½çQAndroidJniObjectï¼å¯ä»¥æ§è¡javaç±»ä¸çæ®éå½æ°ãéæå½æ°ï¼å¯ä»¥ä¼ 类对象jclassãç±»åclassNameãæ¹æ³methodNameãåæ°ï¼ä¹å¯ä»¥æ¿å°æ§è¡ç»æè¿åå¼ã (I)Væ¬å·ä¸çæ¯åæ°ç±»åï¼æ¬å·åé¢çæ¯è¿åå¼ç±»åï¼voidè¿åå¼å¯¹åºVï¼ç±äºStringå¨javaä¸ä¸æ¯æ°æ®ç±»åèæ¯ç±»ï¼æ以è¦ç¨Ljava/lang/String;表示ï¼å ¶ä»ç±»ä½ä¸ºåæ°ä¹æ¯è¿æ ·å¤çã
- è°ç¨å®ä¾æ¹æ³ï¼callMethodãcallObjectMethodã
- è°ç¨éææ¹æ³ï¼callStaticMethodãcallStaticObjectMethodã
- ä¸å¸¦Objectçå½æ°åç¨æ¥æ§è¡æ è¿åå¼æè 常è§è¿åå¼intãfloatççæ¹æ³ã
- å¦æè¿åå¼æ¯Stringæè ç±»åéè¦ç¨å¸¦Objectçå½æ°åæ¥æ§è¡ï¼è¿åQAndroidJniObjectç±»åå转æ¢å¤çæ¿å°ç»æï¼æ¯å¦toStringæ¿å°å符串ã
- åç§åæ°åè¿åå¼ç¤ºä¾ã
package org.qt;
import org.qt.QtAndroidData;
public class QtAndroidTest
{
//éè¦éè¿å®ä¾æ¥è°ç¨ æµè¯åç°ä¸è®º private public æè
ä¸åé½å¯ä»¥è°ç¨ ææ¦
private void printText()
{
System.out.println("printText");
}
public static void printMsg()
{
System.out.println("printMsg");
}
public static void printValue(int value)
{
System.out.println("printValue:" + value);
}
public static void setValue(float value1, double value2, char value3)
{
System.out.println("value1:" + value1 + " value2:" + value2 + " value3:" + value3);
}
public static int getValue()
{
return 65536;
}
public static int getValue(int value)
{
return value + 1;
}
public static void setMsg(String message)
{
System.out.println("setMsg:" + message);
}
public static String getMsg()
{
return "hello from java";
}
public static void setText(int value1, float value2, boolean value3, String message)
{
System.out.println("value1:" + value1 + " value2:" + value2 + " value3:" + value3 + " message:" + message);
}
public static String getText(int value1, float value2, boolean value3, String message)
{
//åæ¶æ¼ç¤ºè§¦åéæå½æ°åç»Qt
QtAndroidData.receiveData("message", "ä½ å¥½å java");
//ä¸é¢ä¸¤ç§åæ³é½å¯ä»¥æ¼å符串
return "value1:" + value1 + " value2:" + value2 + " value3:" + value3 + " message:" + message;
//return "value1:" + String.valueOf(value1) + " value2:" + String.valueOf(value2) + " value3:" + String.valueOf(value3) + " message:" + message;
}
}
#include "androidtest.h"
//java类对åºçå
å+ç±»å
#define className "org/qt/QtAndroidTest"
void AndroidTest::test()
{
jint a = 12;
jint b = 4;
//å¯ä»¥ç´æ¥è°ç¨javaå
置类ä¸çæ¹æ³
jint max = QAndroidJniObject::callStaticMethod<jint>("java/lang/Math", "max", "(II)I", a, b);
//jclass javaMathClass = "java/lang/Math";
jdouble value = QAndroidJniObject::callStaticMethod<jdouble>("java/lang/Math", "random");
qDebug() << "111" << max << value;
}
void AndroidTest::printText()
{
QAndroidJniEnvironment env;
jclass clazz = env.findClass(className);
QAndroidJniObject obj(clazz);
obj.callMethod<void>("printText");
}
void AndroidTest::printMsg()
{
#if 0
//æ¥çæºç å¾ç¥ä¸ä¼ å
¥jclassç±»çå½æ°ä¸å
é¨ä¼èªå¨æ ¹æ®ç±»åæ¥æ¾jclass
QAndroidJniEnvironment env;
jclass clazz = env.findClass(className);
QAndroidJniObject::callStaticMethod<void>(clazz, "printMsg");
#else
//没æåæ°åè¿åå¼å¯ä»¥å¿½ç¥ç¬¬ä¸ä¸ªåæ°
QAndroidJniObject::callStaticMethod<void>(className, "printMsg");
//QAndroidJniObject::callStaticMethod<void>(classNameTest, "printMsg", "()V");
#endif
}
void AndroidTest::printValue(int value)
{
QAndroidJniObject::callStaticMethod<jint>(className, "printValue", "(I)I", (jint)value);
}
void AndroidTest::setValue(float value1, double value2, char value3)
{
QAndroidJniObject::callStaticMethod<void>(className, "setValue", "(FDC)V", (jfloat)value1, (jdouble)value2, (jchar)value3);
}
int AndroidTest::getValue(int value)
{
//javaç±»ä¸æ两个 getValue å½æ° ä¸ä¸ªéè¦ä¼ åæ°
//jint result = QAndroidJniObject::callStaticMethod<jint>(className, "getValue");
jint result = QAndroidJniObject::callStaticMethod<jint>(className, "getValue", "(I)I", (jint)value);
return result;
}
void AndroidTest::setMsg(const QString &msg)
{
QAndroidJniObject jmsg = QAndroidJniObject::fromString(msg);
QAndroidJniObject::callStaticMethod<void>(className, "setMsg", "(Ljava/lang/String;)V", jmsg.object<jstring>());
}
QString AndroidTest::getMsg()
{
QAndroidJniObject result = QAndroidJniObject::callStaticObjectMethod(className, "getMsg", "()Ljava/lang/String;");
return result.toString();
}
void AndroidTest::setText(int value1, float value2, bool value3, const QString &msg)
{
QAndroidJniObject jmsg = QAndroidJniObject::fromString(msg);
QAndroidJniObject::callStaticMethod<void>(className, "setText", "(IFZLjava/lang/String;)V", (jint)value1, (jfloat)value2, (jboolean)value3, jmsg.object<jstring>());
}
QString AndroidTest::getText(int value1, float value2, bool value3, const QString &msg)
{
QAndroidJniObject jmsg = QAndroidJniObject::fromString(msg);
QAndroidJniObject result = QAndroidJniObject::callStaticObjectMethod(className, "getText", "(IFZLjava/lang/String;)Ljava/lang/String;", (jint)value1, (jfloat)value2, (jboolean)value3, jmsg.object<jstring>());
return result.toString();
}
- å¨åçAndroidå¼åä¸ï¼ä¸å页é¢ä¼å®ä¹ä¸åçActivityãä½ä½¿ç¨Qt QuickãFlutterçéç¨Direct UIæ¹å¼å®ç°ç第ä¸æ¹å¼åæ¡æ¶ååªå®ä¹äºä¸ä¸ªActivityãéé¢ä¸å页é¢å®é é½æ¯ä½¿ç¨OpenGLçç´æ¥ç»å¶çãhttps://blog.csdn.net/LCSENs/article/details/100182235
03ï¼11-15
-
å®åä¸ä¸ä¸ªçé¢çªä½å¯¹åºä¸ä¸ªActivityï¼å¤ä¸ªçé¢å°±æå¤ä¸ªActivityï¼èå¨Qtå®åç¨åºä¸ï¼Qtè¿è¾¹åªæä¸ä¸ªActivityé£å°±æ¯QtActivityï¼å åå ¨è·¯å¾ org.qtproject.qt5.android.bindings.QtActivityï¼ï¼è¿ä¸ªQtActivityæ¯åºå®çå好çï¼æ´ä¸ªQtç¨åºé½æ¯å¨è¿ä¸ªQtActivityçé¢ä¸ãä½ æå¼AndroidManifest.xmlæ件å¯ä»¥çå°å¯¹åºèç¹æ个name=org.qtproject.qt5.android.bindings.QtActivityï¼æ以å¦æè¦è®©Qtç¨åºè½å¤æ´æ¹ä¾¿éç çä¸å¯¹åºçjavaç±»è¿è¡äº¤äºï¼éè¦ä¸ä¸æä¼ éActivityçï¼æ¯å¦éå¨ï¼æ¶æ¯æ示çï¼ï¼å»ºè®®æ°å»ºä¸ä¸ªjavaç±»ï¼ç»§æ¿èªQtActivityå³å¯ï¼è¿æ ·ç¸å½äºé»è®¤Qtå¯å¨çå°±æ¯ä½ javaç±»ä¸å®ä¹çActivityï¼å¯ä»¥å¾å¥½çæ§å¶å交äºã
-
ç±äºAndroidManifest.xmlæ件æ¯ä¸ªç¨åºé½å¯è½ä¸ä¸æ ·ï¼ä¸ºäºåæéç¨çç»ä»¶ï¼è¿å°±è¦æ±å¯è½ä¸è½å¸¦ä¸AndroidManifest.xmlæ件ï¼è¿æ ·çè¯æ¯ä¸ªQtå®åç¨åºé½å¯å¨é»è®¤å ç½®çActivityï¼å¦æä¾èµActivityä¸ä¸æçæ§è¡å½æ°éè¦ä¼ å ¥QtçActivityæè¡ï¼è¿éåè®°QtçActivityå åæ¯ Lorg/qtproject/qt5/android/bindings/QtActivity; ä¹å顺ææ³å½ç¶çåç Landroid/app/Activity; åç°æ»æ´»ä¸è¡ï¼åæ¥æ¯å åéäºã
-
ä¸ä¸ªQtå®åç¨åºä¸å¯ä»¥æå¤ä¸ªJavaç±»ï¼å æ¬ç»§æ¿èªActivityçç±»ï¼è¿æ ·çActivityå¯ä»¥éè¿QtAndroid::startActivityå½æ°æ¥è°ç¨ï¼ï¼ä½æ¯åªè½æä¸ä¸ªéè¿AndroidManifest.xmlæ件æå®çActivityï¼ä¸æå®ä¼é»è®¤ä¸ä¸ªãå¦æjavaç±»ä¸ä¸éè¦æ¿å°QtçActivityè¿è¡å¤ççï¼å¯ä»¥ä¸éè¦ç»§æ¿ä»»ä½Activityï¼æ¯å¦å ¨é¨æ¯è¿ç®çéæå½æ°ã
-
å¨javaç±»ä¸å¦æä¸é¢æ²¡æ主å¨å¼å ¥å åï¼åä¸é¢éè¦åå ¨è·¯å¾ï¼å¼å ¥äºåä¸éè¦å ¨è·¯å¾å¯ä»¥ç´æ¥ç¨ï¼å æ¬æ举å¼é½å¯ä»¥ç´æ¥åï¼æ¯å¦ VIBRATOR_SERVICE è¿ç§æ举å¼å¼å ¥äºå ååä¸éè¦åandroid.content.Context.VIBRATOR_SERVICEï¼ï¼å»ºè®®å¼å ¥å åï¼æ¯å¦ä¸é¢åäº import org.qtproject.qt5.android.bindings.QtActivity; åä¸é¢ç»§æ¿ç±»å¯ä»¥ç´æ¥å public class QtAndroidActivity extends QtActivityï¼å¦æ没æå¼å ¥åéè¦åæ public class QtAndroidActivity extends org.qtproject.qt5.android.bindings.QtActivity ã
-
建议æé android studio å·¥å ·å¼åï¼å ä¸ºå¨ android studio ä¸å代ç é½æèªå¨è¯æ³æ示ï¼å åä¼æ示èªå¨å¼å ¥ï¼å¯ä»¥æ¥çæé£äºå½æ°æ¹æ³çï¼è¿å¯ä»¥æ ¡éªä»£ç æ¯å¦æ£ç¡®ï¼èå¦æå¨QtCreatorä¸æåææ¶åå¯è½ä¼åéï¼å°¤å ¶æ¯æ个åæ¯åéï¼å½ç¶è¿ç§é误æ¯ç¼è¯éä¸è¿çï¼ä¼æ示é误å¨åªè¡ã
04ï¼16-20
-
ç¨Qtåå®åå¼åæ大é¾ç¹ä¸¤ä¸ªï¼ç¬¬ä¸ä¸ªå°±æ¯ä¼ åæ°è¿äºå¥å¥æªæªçå符ï¼Ljava/lang/String;ï¼å¥ææï¼å¦ä½å¯¹åºï¼è¿ä¹ä¸æ¯Qtæ æ为é¾åå¦è å¥çï¼å 为è¿å¥å®ä¹æºå¶æ¯å®åç³»ç»åºå±è¦æ±çï¼ç³»ç»å±é¢å®ä¹çä¸å¥è§èï¼å ¶å®è¿ä¸ªå¨å¸®å©ææ¡£ä¸åçå¾æ¸ æ¥ï¼é½ææ°æ®ç±»åå¯¹ç §è¡¨ï¼ç¨çæäºå 次就å¾ç®åäºã第äºä¸ªé¾ç¹å°±æ¯ç¨javaå对åºçç±»ï¼å¦ææ¯ä¼å®åå¼åç人æ¥è¯´é£ä¸è¦å¤ªç®åï¼å°¤å ¶æ¯æç´¢é£ä¹æ¹ä¾¿ä¸å¤§å ï¼æ²¡ææè¿å®åå¼åç人æ¥è¯´å°±éè¦å¦ä¹ ä¸ï¼è¿ä¸ªæ²¡ææ·å¾ï¼åªæ¯å¸æQtè½å¤å°½å¯è½æ大åçå°è£ ä¸äºå¯ä»¥ç´æ¥ä½¿ç¨çç±»ï¼æ¯å¦åæçæ¬å°±æä¾äºæéç³è¯·çç±» QtAndroid::requestPermissionsSync ä¹ç±»çï¼ç¨èµ·æ¥å°±é常çç½ï¼ä¸ç¨èªå·±å个javaç±»è°æ¥è°å»çã
-
ç论ä¸æ¥è¯´æç §Qtæä¾çä¸è½å¤§æ³ç±»QAndroidJniObjectï¼å¯ä»¥ä¸ç¨åjavaç±»ä¹è½æ§è¡åç§å¤çï¼æ¿å°å®ååºä¸çå±æ§åæ§è¡æ¹æ³ï¼å°±æ¯åèµ·æ¥å¤ªç»å¤ªè´¹å²ï¼å¨javaç±»ä¸ä¸è¡ä»£ç ï¼è¿éèµ·ç ä¸è¡ï¼æ以ç»æ大æ³å°±æ¯çæå®åå¼åï¼ç´æ¥å°è£ 好javaç±»è¿è¡è°ç¨ã
-
æµè¯åç°GetStringUTFCharsæ¹æ³å¯¹åºçæ°æ®å符串ä¸ä¸è½å¸¦ætempåæ ·ï¼å¦å解ææé®é¢ï¼ä¸ç¥ä»ä¹åå ã
-
æ°æ®ç±»ååæ°åè¿åå¼ç±»åå¿ é¡»å®å ¨ä¸è´ï¼å¦åæ§è¡ä¼æ示æ¾ä¸å°å¯¹åºçå½æ°ï¼æè¿åå¼ä¸å®è¦åä¸è¿åå¼ã
-
jaræ件对å åçå½å没æè¦æ±ï¼åªè¦æ¾å¨android/libsç®å½ä¸å³å¯ï¼å®ååºå±æ¯éè¿å åå»æ¥æ¾ï¼èä¸æ¯éè¿æ件åï¼ä½ çè³å¯ä»¥å°åæ¥çå åéæ°æ¹æä¹å¯ä»¥æ£å¸¸ä½¿ç¨ï¼æ¯å¦classes.jaræ¹ætest.jarä¹è½æ£å¸¸ä½¿ç¨ã
05ï¼21-25
-
å ³äºæé设置ï¼å¨æ©æçå®åçæ¬ï¼æææéé½åå¨å ¨å±é ç½®æ件AndroidManifest.xmlä¸ï¼è¿ç§å«å®è£ æ¶æéï¼å°±æ¯å®è£ çæ¶ååè¯å®åç³»ç»å½åappéè¦åªäºæéã大æ¦ä»å®å6å¼å§ï¼é¨åæééè¦å¨æç³è¯·ï¼è¿ç§å«å¨ææéï¼è¿ç§ç³è¯·å°çæéä¹å¯ä»¥å¨ææ¤éï¼å°±æ¯è¦æ±ç¨åºå次æ§è¡ä»£ç å»åç³»ç»ç³è¯·æéï¼æ¯å¦æç §ãåå¨è¯»åçãä¹ä¸æ¯ææçæéé½æ¹æäºå¨æç³è¯·ï¼æå³çå ¼å®¹å®å6以ä¸çç³»ç»ä½ æ¢è¦å¨AndroidManifest.xmlä¸åä¸è¦æ±çæéï¼ä¹è¦éè¿checkPermissionç³è¯·ä½ éè¦çæéã
-
android studio æ°å»ºå¹¶ç产jarå æ¥éª¤ã
- 第ä¸æ¥ï¼æ件ï¼Fileï¼-ãæ°å»ºï¼newï¼-ã项ç®ï¼new projectï¼-ã空ç½çªä½ï¼empty activityï¼ã
- 第äºæ¥ï¼åææ°å»ºå¥½ç项ç®é¼ æ å³é®æ°å»ºï¼newï¼-ã模åï¼new moduleï¼-ãå®ååºï¼android libraryï¼ã
- 说æï¼å¦æéæ©çä¸æ¯å®ååºï¼android libraryï¼èæ¯javaåºï¼Java Libraryï¼ï¼åç´æ¥ç¼è¯åºæ¥çå°±æ¯jaræ件ï¼é»è®¤å å com.example.lib.MyClassãæ¨èéæ©javaåºï¼ç¼è¯åä¸ç¨å»ä¸å æ件ä¸æ¾jaræ件ã
- 第ä¸æ¥ï¼å好åºååï¼æ ¹æ®é¡¹ç®éè¦éæ©å¥½æä½sdkçæ¬-ãå®æã
- 第åæ¥ï¼å¨åææ°å»ºå¥½çåºé¡¹ç®mylibraryï¼ä¾æ¬¡æ¾å°åèç¹src/main/java/com.example.mylibraryä¸é¼ æ å³é®æ°å»º-ãclassç±»ãåè®°æ¯è¿ä¸ªèç¹ä¸æ¯javaèç¹æè å ¶ä»èç¹ã
- 第äºæ¥ï¼åå¥½ä½ çç±»æ¹æ³å½æ°çã
package com.example.mylibrary;
public class Test {
public static int add(int a, int b) {
return a + b;
}
}
- 第å æ¥ï¼éä¸åºé¡¹ç®mylibraryï¼èåæ§è¡ç¼è¯ï¼buildï¼-ãç¼è¯åºï¼make module xxxï¼ã
- 第ä¸æ¥ï¼æ¤æ¶å¨mylibrary/buildç®å½ä¸æoutputsç®å½åintermediatesç®å½ï¼å ¶ä¸outputs/aarç®å½ä¸æ¯çæçAndroidåºé¡¹ç®çäºè¿å¶å½æ¡£æ件ï¼å å«ææèµæºï¼class以åresèµæºæä»¶å ¨é¨å å«ãææ¶åæä»¬ä» ä» éè¦jaræ件ï¼åªå å«äºclassæ件ä¸æ¸ åæ件 ï¼ä¸å å«èµæºæ件ï¼å¦å¾ççææresä¸çæ件ãéè¦å°intermediates/aar_main_jar/debugç®å½ä¸ï¼å¯ä»¥çå°classes.jarï¼å°è¿ä¸ªæ·è´åºæ¥ä½¿ç¨å³å¯ãå½ç¶ä½ ä¹å¯ä»¥å¯¹åæçaaræ件ç¨è§£å缩软件解ååºæ¥ä¹è½çå°classes.jarï¼æ¯åä¸ä¸ªæ件ã
- å ¶ä»ï¼è°ç¨jarå é常ç®åï¼åªéè¦å°jaræ件æ¾å¨ä½ ç项ç®çlibsç®å½ä¸å³å¯ï¼å¯¹åºçå ååå½æ°ä¸è¬jarå æä¾è ä¼æä¾ï¼æ²¡ææä¾çè¯ï¼å¯ä»¥å¨android studioä¸æ°å»ºç©ºç½é¡¹ç®ï¼åæ¢å°projectè§å¾ï¼æ¾å°libsç®å½ï¼é¼ æ å³é®æä¸é¢ä½ä¸ºå å¨æåºæ·»å å°é¡¹ç®ï¼å¯¼å ¥å å®æ以åä¼èªå¨å¨libsç®å½ååºï¼åå»ååå¯¼å ¥çå ç¶åå°±èªå¨ååºå¯¹åºçç±»åå½æ°ã
- Qtå®å使ç¨jarå æ¥éª¤ã
- 第ä¸æ¥ï¼å°classes.jaræ¾å°android/libsç®å½ä¸ï¼ä¸ºå¥æ¯è¿ä¸ªç®å½ï¼å 为è¿æ¯å®åçè§å约å®ï¼è¿ä¸ªç®å½å°±æ¯æ¾åºæ件ï¼æ¾å¨è¿ä¸ªç®å½ä¸çæ件ä¼èªå¨æå ç¼è¯å°apkæ件ä¸ã
- 第äºæ¥ï¼è°ç¨jaræ件ä¹åï¼åææ¯ä½ ç¥éjaræ件ä¸çå½æ°è¯¦ç»ä¿¡æ¯ï¼è¿ä¸ªä¸è¬jaræä¾è ä¼æä¾å¥½æåï¼å¦æ代ç 没ææ··è´çè¯ï¼ä½ å¯ä»¥å¨android studioä¸åå»æå¼æ¥é å ·ä½çå½æ°ã
- 第ä¸æ¥ï¼å¦æjaræ件ä¸çå½æ°ç®åï¼ç´æ¥æ¿å°ç»æä¸éè¦ç»æ¥ç»å»ï¼å¯ä»¥ç´æ¥åQtç±»æ¥è°ç¨ï¼å¦æè¿æ¯å¾å¤æï¼å»ºè®®åå»æ°å»ºjavaç±»å¤çå®å交ç»Qtï¼å½ç¶ä¹å¯ä»¥è®©jarçä½è å°½å¯è½å°è£ å½æ°çæ¶åå°±å好ï¼å°½éæä¾æç®åçæ¥å£è¿åéè¦çæ°æ®ãæ¯å¦è¿åå¾çæ°æ®å¯ä»¥åæjarå é¨åå¨å¥½å¾çï¼ç¶åè¿åå¾çè·¯å¾å³å¯ï¼ä¸ç¶æäºæ°æ®è½¬æ¢ä¹æºç¦ã
- 第åæ¥ï¼ç¼åæç»çè°ç¨å½æ°ã
int AndroidJar::add(int a, int b)
{
#ifdef Q_OS_ANDROID
const char *className = "com/example/mylibrary/Test";
jint result = QAndroidJniObject::callStaticMethod<jint>(className, "add", "(II)I", (jint)a, (jint)b);
return result;
#endif
}
- Qt6ä¸å¯¹å®åæ¯æé¨ååäºå¤§çæ¹å¨ï¼ç®åè¿ä¸å®åï¼å¦ææ¯ä¸æ¶åå°ä¸java交äºç纯Qt项ç®ï¼å¯ä»¥æ£å¸¸ç§»æ¤ï¼æ¶åå°çææ¶ä¸å»ºè®®ç§»æ¤å°Qt6ï¼çææç±»å®åäºå说ã
- 移é¤äºå®åæ件androidextrasï¼å°å ¶ä¸é¨ååè½ç±»ç§»å°core模åä¸ï¼ä¸éè¦é¢å¤å¼å ¥ã
- ç±»ååçäºååï¼æ¯å¦QAndroidJniObjectæ¹æäºQJniObjectãQAndroidJniEnvironmentæ¹æäºQJniEnvironmentï¼å¯è½æ¯ä¸ºäºç»ä¸ç§»å¨å¼åå¹³å°ç±»ï¼å¼±åå®åçå½±åã
- 对åºçå®åjdkè¦ç¨jdk11èä¸æ¯jdk1.8ï¼Qt5.15两个é½æ¯æï¼å»ºè®®å°±ç»ä¸ç¨jdk11ã
- 对åºå°è£ çjavaç±»å åå»æäºqt5æ è¯ï¼org.qtproject.qt5.android.bindings.QtActivityæ¹æäºorg.qtproject.qt.android.bindings.QtActivityãorg.qtproject.qt5.android.bindings.QtApplicationæ¹æäºorg.qtproject.qt.android.bindings.QtApplicationã
- 对å®åæä½sdkæè¦æ±ï¼æ以建议å¨é ç½®AndroidManifest.xmlæ件çæ¶åä¸è¦å¸¦ä¸æä½çæ¬è¦æ±ã
- 对AndroidManifest.xmlæ件å 容æè¦æ±ï¼ä¹åQt5å®åçä¸è½å¨Qt6å®åä¸ä½¿ç¨ï¼å ·ä½å 容åè§ç¤ºä¾ä¸çæ件ã
- 对åºç¤ºä¾demoå¨ C:\Qt\Examples\Qt-6.3.0\corelib\platform ç®å½ä¸ï¼ä¹åæ¯ C:\Qt\Examples\Qt-5.15.2\androidextras ï¼ç®åå°±ä¸ä¸ªç¤ºä¾ï¼å¯è½å ä¸ºå ¶ä»ç±»è¿æ²¡æ移æ¤å¥½ã
- Qt6ä¸å®å模åä»ç»å¨è¿é https://doc.qt.io/qt-6/qtandroidprivate.html
- å¦ææ³è¦å®åå ¨å±é®æ¡ä½é¡¶é¨ç¶ææ ï¼å¯ä»¥å¨mainå½æ°ä¸å°showæ¹æshowFullScreenå³å¯ï¼å½ç¶ä¹å¯ä»¥éç¨javaçæ¹å¼å¨onCreateå½æ°ä¸å ä¸è¡ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
06ï¼25-30
-
横ç«å±åæ¢çè¯å«ï¼å¨Qtä¸ä¼åæ¶åæ å°resizeEventäºä»¶ä¸ï¼ä½ å¯ä»¥å¨è¿ä¸ªæ¯å°ºå¯¸ååå读åä¸å½åå±å¹æ¯æ¨ªå±è¿æ¯ç«å±ï¼ç¶åçé¢ä¸ååºè°æ´ï¼æ¯å¦ä¸ä¸æåæ¹æå·¦å³æåã
-
ç±äºä¸åQtçæ¬å¯¹åºçå®åé ç½®æ件 AndroidManifest.xml å å®¹æ ¼å¼ä¸ä¸æ ·ï¼é«çæ¬åä½çæ¬æ¨¡æ¿æ ¼å¼äºä¸å ¼å®¹ï¼æ以建议使ç¨èªå·±çQtçæ¬å建ç AndroidManifest.xml æ件ï¼å建好以åå¦æ使ç¨çæ¯èªå·±éæ°å®ä¹çjavaæ件çå¯å¨çªä½åéè¦å° AndroidManifest.xml æ件ä¸ç android:name="org.qtproject.qt5.android.bindings.QtActivity" æ¢æå°±è¡ã
-
å¦æèªå·±ç¨android studioç¼è¯çjaræ件æ¾å°Qt项ç®çlibsç®å½ä¸ï¼å¯¼è´ç¼è¯éä¸è¿ï¼æ示 com.android.dx.cf.iface.ParseException: bad class file magic ä¹ç±»çï¼é£æ¯å 为jdkçæ¬ä¸ä¸è´å¯¼è´çï¼ä½ å¯è½éè¦å¨android studio项ç®ä¸æ¾å°æ¨¡åç¼jdkçæ¬è®¾ç½®çå°æ¹éä½çæ¬ï¼æ¯å¦ä½ ç¨çndkæ¯r14ï¼åéè¦éæ©jdk1.6æè jdk1.7ãä¸è¬æ¥è¯´é«çæ¬å ¼å®¹ä½çæ¬ï¼å 为ndkçæ¬å¤ªä½æ æ³å ¼å®¹jdk1.8ãåé¢åç°å¦æç´æ¥æ°å»ºçæ¯javaåºï¼Java Libraryï¼åä¸åå¨è¿ä¸ªé®é¢ï¼å¦æéæ©çæ¯å®ååºï¼android libraryï¼å°±å¯è½æè¿ä¸ªé®é¢ã
-
å®å项ç®é ç½®æ件æ¯åºå®çåå AndroidManifest.xml ï¼æ¹æå ¶ä»ååå°±ä¸è®¤è¯ï¼ä¸è¦æ³å½ç¶æ¹æå ¶ä»åå导è´æ æ³æ£å¸¸è¯å«ã
-
AndroidManifest.xmlæ件ä¸çpackage="org.qtproject.example"æ¯å åï¼ä¹æ¯æ´ä¸ªapkç¨åºçå é¨å¯ä¸æ è¯ï¼å¦æå¤ä¸ªapkè¿ä¸ªå åä¸æ ·ï¼åä¼è¦çï¼æ以ä¸å®è¦æ³¨æä¸åçç¨åºè®°å¾æè¿ä¸ªå åæ¹æä½ èªå·±çãè¿ä¸ªå åä¹å³å®äºjavaæ件ä¸éè¦ä½¿ç¨èµæºæ件æ¶åçå¼å ¥å å import org.qtproject.example.R; å¦æå åä¸ä¸æ ·åç¼è¯é½éä¸è¿ã
07ï¼31-35
-
æ°ççqtcæ建å®åå¼åç¯å¢é常ç®åï¼æ©æçæ¬çé常å¤æï¼è¦ä¸ä¸è½½è¥¿ä¸è½½ï¼æè ¾å¥½å¤å¤©æè¡ãç°å¨åªéè¦å®è£ jdkæ件ï¼jdk_8.0.1310.11_64.exeï¼ï¼å ¨é¨é»è®¤ä¸æ¥å°ä½ï¼ç¶åå¨qtcä¸å®åé ç½®çé¢ï¼è®¾ç½®jdkçå®è£ ç®å½ãç¶åæå¼ D:\Qt\Qt6\Tools\QtCreator\share\qtcreator\android\sdk_definitions.json å C:\Users\Administrator\AppData\Roaming\QtProject\qtcreator\android\sdk_definitions.jsonï¼å°éé¢ç cmdline-tools;latest ä¿®æ¹ä¸º cmdline-tools;6.0 ï¼è¿ä¸æ¥éå¸¸å ³é®ï¼é»è®¤æ¯latest导è´å¾ ä¼èªå¨ä¸è½½sdk/ndkçæ¶åä¼ä¸è½½ä¸å ¨ãæ¹å¥½ä»¥åï¼è®¾ç½®sdkä¿åç®å½ï¼åå»å³ä¾§ç Set Up SDK æé®ï¼èªå¨ä¸è½½ä¸å æ件ï¼æåä¸é¢æ个opensslçç®å½æ件ä¹è®¾ç½®ä¸ã该æ件ç½ä¸å¯ä»¥é常ç®åå°±è½ç´æ¥ä¸è½½å°ï¼å³ä¾§å°±ææé®åå»æå¼ä¸è½½é¡µé¢ãç¶åå°±å¯ä»¥å¼å§æå¿«çå®åå¼åä¹æ äºã
-
å ³äºå符串类åç交äºï¼éè¦ç¨ Ljava/lang/String; åè®°åé¢æ个åå·è¡¨ç¤ºå½å对象类åç»æï¼æ¯å¦ QJniObject result = QJniObject::callStaticObjectMethod(className, "getVersion", "()Ljava/lang/String;"); ï¼éé¢çåå·å¿ ä¸å¯ç¼ºï¼è¦æ¯æ¢æ QJniObject result = QJniObject::callStaticObjectMethod(className, "getVersion", "()Ljava/lang/String"); æ§è¡æ¯å¤±è´¥çã
-
å¯ä»¥éè¿ QJniObject::isClassAvailable("com/example/lib/MyClass") æ¥å¤æç±»æ¯å¦å¯ç¨ã
-
å¨å®åçjavaç±»ä¸ï¼å¦ææ¯ç¬ç«çä¸ä¸ªjavaç±»ï¼å¸¸è§çåæ°int/float/stringä¹ç±»çï¼å¨Qtä¸é½é常容æä¼ éåæ°ï¼å¯ç¬çªä½ä¸ä¸æcontextãæ´»å¨çªä½activityã两ç§åæ°æ¯è¾éº»ç¦ï¼å¾å¤äººå°±å°å¨è¿éãå ¶å®Qtå°±æä¾äºå½æ°è·å对åºçå®ä¾ï¼å¨Qt5ä¸æ¯QtAndroid::androidActivity()/QtAndroid::androidContext()ï¼å¨Qt6ä¸æ¯QNativeInterface::QAndroidApplication::context()ãä½æ¯æ没æåç°ï¼å¦ææ¯æ¬¡é½è¿ä¹ä¼ ï¼å¦æå¾å¤å½æ°é½éè¦è¿ä¸ªåæ°ï¼æè§éå¤ä»£ç ä¸å°ï¼æ以强çæ¨è第äºä¸ªæ¹æ³ï¼æ°å»ºçjavaç±»ä¸ï¼æ个private static Context contextï¼ç¶åæä¾ä¸ä¸ªpublic static setContext(Context context)å½æ°ï¼å¨ä¸»çªä½activityå¼å§å建çonCreateå½æ°ä¸ï¼èµå¼xxx.setContextå³å¯ãè¿æ ·å°±ç¸å½äºå¨javaè¿è¾¹ä¼ é好äºå¯¹åºçä¸ä¸ææè çªä½åæ°ï¼ç¶åæ´é²åºæ¥çæ¥å£å°±æ é¡»contextè¿äºåæ°äºï¼çå»äºä¸å°éº»ç¦ã
//javaç±»ä¸å½æ°åå
public static void getBattery(Context context)
//qt5ç±»ä¸è°ç¨
QAndroidJniObject::callStaticMethod<void>("org/qt/QtAndroidReceiver", "getBattery", "(Landroid/content/Context;)V", QtAndroid::androidActivity().object());
//qt6ç±»ä¸è°ç¨
QJniObject::callStaticMethod<void>("org/qt/QtAndroidReceiver", "getBattery", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context());
//æ¹æ³2éè¿å¯å¨çªä½èµå¼åè°ç¨
public class abc
{
private static Context context;
public static void setContext(Context context)
{
abc.context = context;
}
public static void getBattery()
{
abc.context.xxx;
}
}
//ä¸é¢è¿ä¸ªçªä½ä½ä¸ºå¯å¨çªä½
public class QtAndroidActivity extends QtActivity
{
//å¿
é¡»å¨çªä½å建çæ¶åä¸é¢èµå¼
@Override
public void onCreate(Bundle savedInstanceState)
{
abc.setContext(getApplicationContext());
}
}
//qtç±»ä¸è°ç¨å°±æ¹ä¾¿äº/å¦ææå¾å¤ä¸ªå½æ°é½éè¦ä¼ å
¥contextåæçå¯ä»¥å¤§å¤§æå
QJniObject::callStaticMethod<void>("org/qt/QtAndroidReceiver", "getBattery", "()V");
4 ffmpegä¸ä½ç»éª
- ffmpegçåºæé¾æ¥é¡ºåºè¦æ±ï¼å¦æä¸æç §é¡ºåºæ¥ï¼ä¹è®¸å¨windowsä¸æ²¡æé®é¢ï¼ä½æ¯å°äºunixç³»ç»å¾å¯è½æé®é¢ï¼æ¥éæ示äºéé¾éçæ¾ä¸å°åå ã顺åºåç §ffmpegèªå¸¦ç¤ºä¾ä¸çç¼è¯é¾æ¥é¡ºåºå³å¯ãæ£ç¡®é¡ºåºæ¯ LIBS += -L/ -lavformat -lavfilter -lavcodec -lswresample -lswscale -lavutil -lavdevice ãä¸æ¯ææçåºé½æ¯å¿ é¡»çï¼æ¯å¦avdeviceåºï¼å¦æ代ç ä¸æ²¡ç¨ä¸ä¹æ²¡å¼ç¨ï¼å¯ä»¥ä¸éè¦ã
- ffmpeg解ç ä¸ï¼av_find_best_stream第äºä¸ªåæ°ä¼ å ¥AVCodecçè¯ï¼å°±ç´æ¥è·åå°äºå¼ï¼èä¸ç¨avcodec_find_decoderæ¥å¤çã
- ffmpegå¨è§£ç çæ¶åï¼avcodec_alloc_context3çåæ°AVCodecä¸æ¯å¿ é¡»çï¼å¦æè¿éæ¯NULLï¼åä¸é¢avcodec_open2çæ¶åå°±å¿ é¡»ä¼ å ¥ãç¼ç çæ¶åå¨avcodec_alloc_context3çæ¶åå¿ é¡»ä¼ å ¥ï¼å¦åä¸é¢æå¼å¤±è´¥ã
- 解ç é¶æ®µï¼æ¯æ¬¡av_read_frameåï¼ä½¿ç¨å®å¯¹åºçpacketæ°æ®ï¼å¿ é¡»è°ç¨av_packet_unrefï¼å¦åå åæ³æ¼ãç¼ç é¶æ®µï¼æ¯æ¬¡av_write_frameåï¼éé¢ä¼èªå¨è°ç¨av_packet_unrefã
- avpacket表示å缩çè§é³é¢æ°æ®ï¼è§£ç ååç¼ç åï¼ï¼avframe表示æªå缩çè§é³é¢æ°æ®ï¼è§£ç ååç¼ç åï¼ï¼è§é³é¢æ件以åä¼ è¾é½æ¯ä½¿ç¨å缩çæ°æ®ï¼æ¶å°æ°æ®è§£ç åææ¯æªå缩çæ°æ®ï¼æè½ç´æ¥ç»å¶åææ¾ã
- 解ç 对åºav_read_frame/avcodec_send_packet/avcodec_receive_frameï¼ç¼ç 对åºavcodec_send_frame/avcodec_receive_packet/av_write_frameãå¯ä»¥çå°å½åé常è§æ´ï¼ç¼ç å好å解ç 顺åºç¸åã
- avcodec_send_packetåavcodec_receive_frame并ä¸æ¯ä¸ä¸å¯¹åºçè°ç¨å ³ç³»ï¼èæ¯ä¸ä¸ªavcodec_send_packetçè°ç¨ï¼å¯è½ä¼å¯¹åºå¤ä¸ªavcodec_receive_frameå½æ°çè°ç¨ãå 为解ç å¨å é¨æ¯æç¼åååè帧çï¼å¹¶ä¸æ¯æ¯éè¿å»ä¸ä¸ªæ°æ®å å°±è½è§£ç åºä¸å¸§æ°æ®ï¼å¯è½åºç°éè¿å»å 个æ°æ®å ï¼ä½æ¯ææ¶æ²¡ææ°æ®å¸§è§£ç è¾åºçæ åµï¼ä¹å¯è½ä¼åºç°æ个æ¶é´ç¹éè¿å»ä¸ä¸ªæ°æ®å ï¼ç¶åä¼è¾åºå¤ä¸ªæ°æ®å¸§çæ åµãä½æ¯å®é 使ç¨è¿ç¨ä¸ä½ ä¼åç°ä½ éå°è¿ç99.9%çè§é³é¢æ件æè æµé½æ¯ä¸å¯¹ä¸å ³ç³»ï¼ä¸ä¸ªavcodec_send_packet就对åºä¸æ¬¡avcodec_receive_frameã
- å¨ffmpegå½æ°æ¥å£ä¸ï¼æä¸å°å¸¦æ°åç»å°¾çå½æ°ï¼æ¯å¦avcodec_alloc_context3ãavcodec_decode_video2ãavcodec_decode_audio4ï¼è¿ç§ä¸è¬å°±æ¯ä¸æè¿ä»£çç»æãæ¯å¦æ©æçæ¬å¾å¯è½æ个å½æ°avcodec_alloc_contextï¼ä½æ¯åé¢åæ°å¢äºæ´å®åçå½æ°ï¼åå¸æç¨æ·è½å¤å¿«éæ¾å°è¯¥å½æ°ï¼æ以ç´æ¥åé¢å 个æ°åç¨ä»¥åºåãè¿åºæ¬ä¸é½æ¯ç¨åºåçæ¯ä¾ãå¦ææ¯å¤§çæ¬çæ´æ°ï¼å¯è½æ§çå½æ°ä¼ä¸»é®åºå¼ï¼çè³ç§»é¤ãä¸è¬å»ºè®®ç¨æ°çå½æ°æ¥å£ã
- ä¼å¤çé³è§é¢æ ¼å¼ï¼æ¯ä¸ºäºåç§åºç¨åºæ¯éæ±äº§ççï¼ä¹æ¯éçæ¶ä»£çåå±éè¦åºè¿èççï¼ä¸»è¦å°±æ¯ä¸ºäºæ¹ä¾¿å缩åä¼ è¾ï¼ç»è¿åç§åæ ·çç®æ³æ åãå¨ffmpegä¸ï¼éç¨ç解ç åæ³é½æ¯å°ä»»æè§é¢æ ¼å¼è§£ç 转æ¢æyuvï¼è½¯è§£ç ï¼æè nv12ï¼ç¡¬è§£ç ï¼æ°æ®ï¼ä»»æé³é¢æ ¼å¼è½¬æ¢æpcmæ°æ®ï¼yuv/nv12/pcmå 为æ¯åå§çæ°æ®ï¼æ以ä½ç§¯é常大ï¼ä¼ç¹å°±æ¯é常éç¨ï¼å¯ä»¥ç´æ¥æ¾ç¤ºåææ¾ã
- è¦åé³è§é¢æ ¼å¼ç转æ¢ï¼éç¨åæ³å°±æ¯è§é¢è§£ç æyuvï¼é³é¢è§£ç æpcmï¼ç¶ååç±yuvç¼ç æå ¶ä»è§é¢æ ¼å¼ï¼å¯¹åºè½¬æ¢å¯¹è±¡SwsContextï¼ï¼pcmç¼ç æå ¶ä»é³é¢æ ¼å¼ï¼å¯¹åºè½¬æ¢å¯¹è±¡SwrContextï¼ï¼ä¸åä¸ç¦»å ¶ä¸ï¼å¯ä¸åºå«å°±æ¯ä¸åæ ¼å¼å¯¹åºçåç§åæ°ä¸ä¸æ ·ãé³é¢è½¬æ¢è¿åå¯è½è¿éè¦ééæ ·ã
- æ 论æ¯ffmpegæºç æ¬èº«è¿æ¯æä¾ç示ä¾demoï¼ä¼åç°éé¢å¤§é¨åç代ç é½æ¯å¨åå¤æï¼æ¯å¦å¯¹è±¡æ¯å¦åé okï¼å¤§é¨åé½æä¾è¿åå¼ï¼è´æ°è¡¨ç¤ºå¤±è´¥ï¼æ¯ä¸æ¥æ§è¡åé½éè¦å¤ææ¯å¦okå继ç»ãå ¶å®è¿ç§åæ³æ¯é常è§èèä¸æå¿ è¦çï¼å¯ä»¥é¿å ç¨åºæå¤å´©æºæ®µé误ï¼èä¸å°±ç®åºéä¹å¯ä»¥éå¸¸æ¸ æ°çç¥éå ·ä½å¨åªä¸æ¥ï¼åµä¸è¿å¢å äºä»£ç è¡æ°ï¼ä½ä¹èä¸ä¸ºãé£æäºäººåè¦æ å¿è¿ä¼åæ ¢ç¨åºè¿è¡é度ï¼æ¯ç«ç»å¤§é¨åçå¤æé½æ¯ä¸ä¼åºç°çï¼è¿éå¯ä»¥å¾è´è´£ä»»çåè¯ä½ ï¼è¿ä¸ªifå¤æï¼å ç¨æ¶é´å¿½ç¥ä¸è®¡ï¼è³å°å¨çº³ç§çº§å«ãèä¸ä¸ºäºæé«ç¨åºçå¥å£®æ§ç¨³å®æ§ï¼å¾æå¿ è¦ï¼å°¤å ¶æ¯C/C++è¿ç±»ç¨åºã
- å¾å¤åå¦è è§å¾ffmpegå¾å¤æï¼å½æ°æ¥å£å¤ªå¤ï¼æè æµç¨ç¹çï¼ä¸ºä»ä¹ä¸æä¾ä¸ä¸ªç®æçæ¥å£å¢ï¼å ¶å®å®å ¨å¯ä»¥æä¾ï¼åªæ¯å¨è¦åæ§è¿å为äºå°å个ç»ä»¶ç¬ç«ï¼æ以æä¼æååºæ¥åç§åºåæ¥å£ãå ¶å®å°±æ¯æ½è±¡åºæ¥ä¸ºäºåç§åºæ¯éæ±ï¼æ¯å¦è§£ç çæ¶åï¼éè¦å éè¿avformat_find_stream_infoè·åæµä¿¡æ¯ï¼ç¶åå°æµä¿¡æ¯ä¸çcodecparå¤å¶ç»AVCodecContextï¼å¨av_read_frame读åå°æ°æ®å¸§åï¼å¨è§£ç è°ç¨avcodec_send_packet/avcodec_receive_frameçæ¶åå°±éè¦è¿ä¸ªAVCodecContextï¼è¿ä¸ªæµç¨æ°¸è¿å¦æ¤ï¼ä¸ºä»ä¹ffmpegä¸å é¨å¤çå°å¤å¶å¢ï¼ä»¥ä¸ºAVCodecContextè¿å¯ä»¥ç¨äºç¼ç ï¼èä¸åç§åæ°ä¿¡æ¯å¯è°ï¼åæ¶ä¹æ¯ä¸ºäºåAVStream以åå ¶ä»ç¬ç«å¼æ¥ï¼å 为没æAVStreamä»ä¹å¯ä»¥å®æç¼è§£ç ï¼åªè¦ç»å°ä»éè¦çä¿¡æ¯å°±è¡ãéçä½ ä½¿ç¨çæ·±å ¥ï¼ä¼åç°è¿ç§è®¾è®¡ææ¯ææ£çã
5 Qt设计模å¼
读ãc++ Qt设计模å¼ã书ç±æ´ççä¸ç¹ç»éªãæ¤ä¹¦åå®æ¹çãC++ GUI Qt4ç¼ç¨ãä¸èµ·çã
- é常èè¨ï¼å¥½çåæ³æ¯å¨å å«äºQt头æ件ä¹ååå å«éQt头æ件ï¼ç±äºQtï¼ä¸ºç¼è¯å¨åé¢å¤çå¨ï¼å®ä¹äºè®¸å¤ç¬¦å·ï¼è¿ä½¿å¾é¿å å称å²çªåå¾æ´å®¹æï¼ä¹æ´å®¹ææ¾å°æ件ã
#include "frminput2019.h"
#include "ui_frminput2019.h"
#include "qdatetime.h"
#include "qdebug.h"
#include "input2019.h"
#include "inputnumber.h"
- ä¸ç§å¥½çç¼ç¨å®è·µæ¯å¨ä»£ç ä¸ä½¿ç¨constå®ä½èä¸æ¯åµå ¥æ°åå常éï¼ææ¶ç§°ä»ä»¬ä¸ºâå¹»æ°âï¼ãå¦æ以åéè¦ä¿®æ¹ä»çå¼æ¶ï¼å°±å¯ä»¥è·å¾è¿ç§çµæ´»æ§ãä¸è¬èè¨ï¼å°å¸¸éâå¤ç«âåºæ¥ï¼å¯æé«ç¨åºçå¯ç»´æ¤æ§ã
//ä¸æ¨èåæ³
for (int i = 0; i < 100; ++i) {
...
}
//æ¨èä¸é¢çåæ³
const int count = 100;
for (int i = 0; i < count; ++i) {
...
}
-
å å管ç使ç¨åºåè·å¾äºå¼ºå¤§çè½åï¼ä½æ¯ï¼âæåè¶å¤§ï¼è´£ä»»è¶å¤§âã
-
åªè¦æå¯è½ï¼å°±åºå½ä½¿ç¨å表èä¸æ¯æ°ç»ï¼æ¯å¦åºè¯¥ä½¿ç¨ QList
ä»£æ¿ int [] ï¼å¨c++ä¸æ°ç»è¢«çææ¯âéªæ¶çâã -
å¨å©ç¨Qtç¼åç¨åºçè¿ç¨ä¸ï¼å 为Qtçç¶åæææ继æ¿å ³ç³»ï¼å¾å°ä¼ç¨å°æºè½æéï¼å 为éè¦è°ç¨deleteçæ åµå¾å°ãä»»ä½æ¶ååªè¦æ们éè¦è°ç¨deleteï¼æè æ¯éè¦å°æ个æé设å®ä¸º0æ¶ï¼åºè¯¥èè使ç¨ä¸ä¸ªæºè½æéã
-
å®é ä¸ï¼æ们ä¸è½å®å ¨ç¡®å®ä½¿ç¨å¤çº¿ç¨å°±ä¸å®è½å¤çæ£æ¹åç¨åºçæ§è½ï¼ä¾å¦ï¼å¦æå¢å 使ç¨çº¿ç¨çæ°éï¼ä½¿ä»ä¸ç³»ç»å¯ç¨çå æ ¸æ°éææ£æ¯ï¼è¿æ ·åæ许è¿ä¼éä½ç¨åºçæ§è½ï¼å 为æè·å¾çæ¶çä¼å 线ç¨ç«äºçå§å¢èæ¶å¤±æ®å°½ãææ¶åï¼å线ç¨ä¸æææçç®æ³å¨å¤çº¿ç¨ä¸å´ä¸ä¸å®ææãå æ¤ï¼å¦æççæ¯æ³æ¹è¿ç¨åºçæ§è½ï¼çæ³çåæ³æ¯ï¼ä½¿ç¨ä¸åçå®ç°æ¹æ³ï¼å¹¶ä¸ä»ä»¬çæ§è½è¿è¡æ¯è¾åå 以åç±»ï¼å½ç¶æµè¯å¯¹æ¯çåææ¯ä½¿ç¨å®å ¨ç¸åç硬件å软件é ç½®ç¯å¢ã
-
å¨æºä»£ç ä¸å ³äºæ件路å¾ï¼ä½¿ç¨ / ä¼æ´æ¹ä¾¿ä¸äºï¼å 为æ 论æ¯å¨ä½ç§å¹³å°ä¸ï¼Qté½è½ç解ä»ï¼ä¸éè¦å¯¹ä»è¿è¡è½¬æ¢ãä½æ¯ï¼å½æ们æ³ä¸ºç¨æ·æ¾ç¤ºè·¯å¾æ¶ï¼æ好è¿æ¯æ ¹æ®åºç¨ç¨åºæå¨å¹³å°çæ£ç¡®å½¢å¼æ¥æ¾ç¤ºä»ã
-
å½æ们æå¾å¤é¡¹æ°æ®éè¦å¤çæ¶ï¼æ¯å¦æåä¸ä¸æè æ´å¤ï¼é£ä¹ä¸ºæ¯ä¸ªå¤çé½å建ä¸ä¸ªçº¿ç¨å¯è½å¯¼è´å¤§éçå¼éï¼è¿æ ·æ¥ä¾æ¬¡å¤çæ°æ®æ许æ´å¿«äºãä¸ç§è§£å³åæ³å°±æ¯å建å°éçè¾ å©çº¿ç¨ï¼å¹¶è®©æ¯ä¸ªçº¿ç¨åªå¤çä¸ç»æ°æ®ã
6 Qt大佬ä¸åº
6.1 é ·ç 大佬
微信ï¼Kuma-NPC
- å ³äºQtäºä»¶ä¼ éçä¸ä¸ªè¯´æï¼
- é常åwin32ç¨åºï¼é¼ æ æ¶æ¯åºè¯¥æ¯ç´æ¥åç»æå®çªå£å¥æçï¼æå®çªå£æ²¡æå¤çå°±ä¼è½¬åæéä¼ æ¶æ¯ï¼äº¤ç»ç¶çªå£å¤çãä½ å¨ä¸ä¸ªæ®éæålabelä¸ç¹å»ï¼ç¶çªå£ä¹è½æ¶å°é¼ æ äºä»¶ã
- Qtåºè¯¥æ¯æææ¶æ¯é½åç»äºé¡¶å±çªå£ï¼æ以äºä»¶ååé»è¾æ¯èªå·±å¤çï¼ä¸»çªå£æ¶å°é¼ æ äºä»¶ç¶åQtèªå·±ååç»æå®åæ§ä»¶ï¼QEventä¼æignoreæè accept表示èªå·±å¤çäºæ²¡æï¼ä¾å¦é¼ æ ç¹å»äºä»¶ï¼äºä»¶ååå¨åç°æ²¡æ被å¤çï¼æ°æ®éæ°è®¡ç®ç¶åååç»ç¶çªå£ãè¿æ ·ç¶çªå£æ¶å°çäºä»¶åæ å°±æ¯åºäºèªå·±çªå£å çãç¨eventFilterå°±éè¦èªå·±è®¡ç®åæ ã
- åæ¯å¦ï¼å½ä½¿ç¨QDialogï¼æ¾ä¸ä¸ªQLineEdit并设置ç¦ç¹ï¼æEscæ¶QDialogä¹ä¼èªå¨å ³éï¼æ¬è´¨ä¸å°±æ¯å 为QLineEdit并ä¸å¤çEscçæé®äºä»¶ï¼éä¼ ç»äºQDialogã
6.2 å°è±å
-
æ è®ºä½ æ¯å¦Qtï¼Javaï¼Pythonæå ¶å®ï¼é½éè¦æç½ä¸ä¸ªéçï¼æå¼æä½ ç好å¥å¿ï¼åä¸ä¸è¦å»è¿½æ±ç¬¬ä¸æ¹ç±»æå·¥å ·æ¯æä¹å®ç°çï¼è¿å¾å¾ä¼è®©ä½ æ¶æçå¾®ï¼å ¶å®ï¼ä½ åªéè¦çç»ææ¡å®çæ¥å£ï¼ç¥éç±»çç®çå³å¯ï¼ä¸å¯ç¯é¢åè¿ç¨çæ¯ç ï¼å¨æ ¹é®åºãè®°ä½ï¼ä½ çç®æ æ¯è®©å ¶å®å·¥å ·ä¸ºä½ æå¡ï¼ä½ è¦è¸©å¨å·¨äººçè©èä¸åé ä¸çã
-
Qtçæ£çæ ¸å¿ï¼å 对象系ç»ãå±æ§ç³»ç»ã对象模åã对象æ ãä¿¡å·æ§½ãå¾æ»éåè¿äºå¤§ç¹æ§ï¼å¨ä½ ç项ç®ä¸ï¼éæ¸ç设æ³å å ¥è¿äºç¹æ§ï¼å¤å¤ç»ä¹ 使ç¨å®ä»¬ï¼é¿æ¤ä»¥å¾ä½ ä¼æ¶è·ææ³ä¸å°çææã
-
ä¸è¾¹è¯·æå«äººï¼ä¸è¾¹å¤å¤éæï¼å ¶å®ç¼ç è¿æ¡è·¯è½ç¶æ人ç»ä½ æè·¯ï¼ä½çæ£èµ°ä¸å»çæ¯ä½ èªå·±ï¼å½ä½ çæ£èµ°å®æ¶ï¼ä½ çç¼ç æ°´å¹³ä¸å®ä¼æé常大çæåãä¹è®¸å«äºº1000è¡ç代ç ï¼å¨ä½ è¿éå åè¡å°±æå®äºï¼è¿ä¹æ£äºQtçé åã
-
å¨é 读Qtç帮å©ææ¡£æ¶ï¼è¦éä¸å¿æ¥ï¼ä¸è¦æ¾è¿æ¯ä¸å¥ï¼è®°ä½å¨ææ¡£ä¸æ²¡æåºè¯ï¼å°¤å ¶æ¯æ¯æ®µçå¼å¤´ã
7 å ¶ä»ç»éª
-
Qtççä¸æä¹±ç é®é¢ï¼çæ¬ä¼å¤å¯¼è´çå¦ä½éæ©å®è£ å é®é¢ï¼å¦ä½æå åå¸ç¨åºçé®é¢ï¼å ªç§°Qtççä¸åº§å¤§å±±ï¼
-
å¨Qtçå¦ä¹ è¿ç¨ä¸ï¼å¦ä¼æ¥ç对åºç±»ç头æ件æ¯ä¸ä¸ªå¥½ä¹ æ¯ï¼å¦æå¨è¯¥ç±»ç头æ件没ææ¾å°å¯¹åºçå½æ°ï¼å¯ä»¥å»ä»çç¶ç±»ä¸æ¾æ¾ï¼å®å¨ä¸è¡è¿æç·ç·ç±»ï¼è¯å®è½æ¾å°çãéè¿å¤´æä»¶ä½ ä¼åç°å¾å¤å½æ°æ¥å£å ¶å®Qtå·²ç»å¸®æ们å°è£ 好äºï¼æ空è¿å¯ä»¥é 读ä¸ä»çå®ç°ä»£ç ã
-
Qtå®è£ ç®å½ä¸çExamplesç®å½ä¸çä¾åï¼çå®å¦å®ï¼æèª20Kèµ·æ¥ï¼Qt常ç¨ç±»ç头æ件çå½æ°çå®å¦å®ä½¿ç¨ä¸é并å 以èä¼è´¯éï¼æèª30Kèµ·æ¥ã
-
Qtå¨å¼åé¶æ®µä¸æ¯æä¸æç®å½ï¼è¿è¡é¶æ®µå¯ä»¥ï¼æ¯å¦æå åå¸çç¨åºæ¾å°ä¸æç®å½è¿è¡æ¯okçï¼ï¼åè®°ï¼è¿æ¯æ æ°äººå¯è½ç¯çé误ï¼å¨å®è£ Qtéæå¼åç¯å¢ä»¥åç¼è¯å¨çæ¶åï¼å¡å¿ è®°å¾ç®å½å¿ é¡»è±æï¼Qt项ç®æºç ä¹å¿ é¡»æ¯è±æç®å½ï¼å¦åå¾å¯è½ä¸æ£å¸¸ï¼å»ºè®®å°½éç¨é»è®¤çå®è£ ä½ç½®ã
-
ç¨åºå¦æåºç°å´©æºå段é误ï¼90%é½æ¯å 为è¦ä¹è¶çï¼ä¸è¬æ¯æç´¢å¼è¶çï¼æ¯å¦æ°ç»æéå大å°5ï¼å第6个å¼ï¼ï¼è¦ä¹æªåå§åï¼ä¸è¬ææé没ænewåé ï¼æè åé ååéæ¾äºï¼ç¶ååå»ä½¿ç¨è¿ä¸ªæéï¼ï¼æ»æ£è¿ä¸¤ç¹ï¼90%çé®é¢è§£å³äºã
-
Qtä¸å ±æå ç¾ä¸ªçæ¬ï¼å ³äºå¦ä½éæ©Qtçæ¬çé®é¢ï¼æä¸è¬ä¿çå个çæ¬ï¼ä¸ºäºå ¼å®¹Qt4ç¨4.8.7ï¼æåçæ¯æXPççæ¬5.7.0ï¼ææ°çé¿ææ¯æçæ¬æ¯å¦5.15ï¼æé«çæ°çæ¬æ¯å¦5.15.2ã强çä¸å»ºè®®ä½¿ç¨4.7以åå5.0å°5.3ä¹é´ççæ¬ï¼Qt6.0å°Qt6.2ä¹é´ãä¸å«6.2ççæ¬ä¹ä¸å»ºè®®ï¼å¾å¤æ¨¡åè¿æ²¡æéæï¼ï¼å¤ªå¤bugååï¼ç¨³å®æ§åå ¼å®¹æ§ç¸æ¯äºä¹åççæ¬ç¸å½å·®ï¼è½æ¢å°±æ¢ï¼ä¸è½æ¢ç¡æé¢å¯¼ä¹è¦æ¢ãå¦æ没æåå²å 袱建议ç¨5.15.2ï¼ç®åæ°æ¨åºç6.0çæ¬ä¹å¼ºçä¸å»ºè®®ä½¿ç¨ï¼å®æ¹è¿å¨æ´åå½ä¸ï¼å¥½å¤ç±»å模åææ¶æ²¡ææ´åï¼éè¦çå°6.2.2çæ¬åç¨ãèèå°qssæ§è½ä»¥åèªå¸¦mysql驱å¨çå ç´ ï¼æç»Qt5éç¨5.12.3ï¼Qt4éç¨4.8.7ï¼Qt6éç¨6.5.xã
-
Qtåmsvcç¼è¯å¨å¸¸è§æé æ¯Qt5.7+VS2013ãQt5.9+VS2015ãQt5.12+VS2017ãQt5.15+VS2019ãQt6.2+VS2019ï¼æç §è¿äºæé æ¥ï¼åºæ¬ä¸å¸¸ç¨ç模åé½ä¼æï¼æ¯å¦webengine模åï¼å¦æéç¨çQt5.12+msvc2015ï¼åå¾å¯è½å®æ¹æ²¡æç¼è¯è¿ä¸ªæ¨¡åï¼åªæ¯ç¼è¯äºQt5.12+msvc2017çï¼å¦æä¸å®è¦ç¨msvc2015ä¸æ³æ¢msvc2017ååªè½éæ©Qt5.9+msvc2015å¥ä»¶ï¼æè èªè¡æºç éæ°ç¼è¯ï¼è¿ä¸ªé¾åº¦è¶ 大ï¼åå¦è ç»è¿ï¼ã
-
Qté»è®¤æ对åºVSçæ¬ï¼å¨ä¸è½½å¯¹åºVSæ件çæ¶åå¿éè¦æ个æ°ï¼å®æ¹é»è®¤æä¾çæ¯åé çæ件ï¼å¦ææ³è¦Qt4.8+VS2015çæ件ï¼éè¦èªè¡ç¼è¯ãä¸è¬æ¥è¯´æ¯Qt4.8åé VS2010ï¼Qt5.6åé VS2013ï¼Qt5.9åé VS2015ï¼Qt5.12åé VS2017ï¼Qt5.15åé VS2019ï¼åè®°ï¼åé æ好ã
-
ç¨Qtåå¼åæºå¨å»ºè®®ç¨win10ï¼å°¤å ¶æ¯2021年以åæ°åå¸çQtçæ¬ï¼æ¯å¦Qt5.12.12ãQt5.15.2ãQt6.2.2çï¼å 为å¾å¯è½èªå¸¦çQtCreatorç¨çææ°ççæ¬ï¼Qt6å¼å§ä¸åæ¯æwin7ï¼æè ç±äºå ¶ä»çåå ï¼å¯¹win7çæ¯æä¸å好ï¼ä¼åºç°å¥å¥æªæªçé®é¢çï¼æ以åæ¯æ²¡å¾éå¿ é¡»ç¨win10ã建议åä½æ¥æ±æ°æ¶ä»£çååï¼è¿ä¸ä¸å¯ä¸ä¸åçåªæååã
-
æ°çæ¬Qtå®è£ å å®è£ çæ¶åéè¦å¡«å注åä¿¡æ¯ï¼å¦æä¸æ³å¡«åï¼å ç¦ç¨ç½å¡ï¼å¨è¿è¡å®è£ å ï¼å¯ä»¥ç´æ¥è·³è¿è¿ä¸æ¥è¿è¡å®è£ ãä»Qt5.15å¼å§ä¸åæä¾ç¦»çº¿å®è£ å ï¼æå³çå¿ é¡»ä½¿ç¨å¨çº¿å®è£ å¨å®è£ Qtçåç»çæ¬ï¼å¿ 须填åç¨æ·ä¿¡æ¯ï¼æ²¡å¾éã
-
ç»æç§ç±ï¼å¦æéå°é®é¢æç´¢Qtæ¹é¢æ¾ä¸å°çæ¡ï¼è¯çå°å ³é®åç¨JAVA C# androidæ头ï¼ä½ ä¼åç°å«æä¸çªå¤©å°ï¼å ¶ä»äººå ¶ä»è¯è¨å ¶ä»é¢åå¾å¯è½åè¿ï¼
-
å¦æQtè½ä»ä¸é¢å 个æ¹é¢åªåï¼ç¸ä¿¡ä¼æ´æåå±åæ¯ã
- QWidgetæ¯æCSS3ï¼å ·æ诸å¤ççé¼çææï¼ç®åæ¯æçæ¯CSS2ã
- QWidgetæ¯æGPUç»å¶ï¼å¯éåæ¢CPUæè GPUï¼æåç»å¶æçï¼å©ç¨ç°å¨å¼ºå¤§ç硬件ã
- Qmlæ ç¼æ¯æjsï¼å¯ä»¥å©ç¨ç°å¨åç§jsè½®åï¼ææ°çº§æåqmlç项ç®èå´ã
- æ¯æå°ç¨åºè½¬æwebè¿è¡ï¼æ¯å¦è½¬æcgiä¹ç±»çç¨åºï¼ç®åQt for WebAssemblyå¾é¸¡èï¼åè½æå ¶æéï¼sql/network/æ¬å°è®¿é®çé½ä¸æ¯æï¼é¦æ¬¡å è½½éåº¦è¶ æ ¢ï¼å¤§é¨åQtç±»è¿ä¸æ¯æã
- Qtèªä»4.7以åå¼å ¥çQMLãä»æ¤ä»¥åï¼Qtå¼åå°±åæäºä¸¤ç§æµæ´¾ï¼ä¸ç§ä½¿ç¨åæ¥çC++ è¯è¨è¿è¡å¼åï¼å¦å¤ä¸ç§ä½¿ç¨QMLè¯è¨è¿è¡å¼åãè¿ä¸æå¾åï¼ç»å¸¸åµåµä¸äº¦ä¹ä¹ï¼å¨Qtçä»æ¤å°±æ两大éµè¥äº§çæ¿çç纷äºï¼é£å°±æ¯éç¨qmlè¿æ¯widget好ï¼å¤§éåå¦è ä¹ä¼é®è¿ä¸ªé®é¢ï¼æ以ä¸å ç¹æ»ç»ã
- widgetå±äºä¼ ç»çé¢å¼åï¼åVB/VC/Delphiçææ³æ§ä»¶å¼å类似ï¼èµ°CPUç»å¶ï¼è½æ大åçå ¼å®¹ç°æç硬件åè¿å»çç¸å¯¹åä½æ§è½ç硬件ã
- qmlå±äºæ°æ¶ä»£ç产ç©ï¼å¤§æ¦ä»2010å¹´å¼å§ï¼åflutter/Electronçwebå¼åæ¡æ¶å移å¨å¼åæ¡æ¶ç±»ä¼¼ï¼ä¸ºäºéåºåç§ç§»å¨ç«¯å¼ååå¨ç»æµç æ§è§¦æ¸ä¸æ»ä½éªãå åå©ç¨åâ榨干âç°å¨çGPUæ§è½ï¼æCPUçåºæ¥ç»ç¨æ·æ大ååæ¥ã
- 硬件æ§è½è¶å¥½ï¼GPUè¶æ¯å¼ºå²ï¼qmlç综åæ§è½è¶æ¯å®çwidgetï¼åä¹å¯¹æ¯ä¹æ¯ææ°çº§çãé¤äºæå ¶çææ¬çåµå ¥å¼ç¡¬ä»¶é¢åæè å½äº§CPUçï¼å ¶ä»é¢åç硬件æ§è½é½æ¯æ´å¢ã
- widget主è¦éä¸å¨éèãåå·¥ãå®é²ãèªå¤©ãè¹è¶ãæè²çé¢åï¼qml主è¦éä¸å¨æ±½è½¦ä»ªè¡¨ã车æºãç´æçé¢åã
- ç®åå½å widgetå¤äºqmlï¼å½å¤å¯è½ååqmlï¼è¿ä¸ªä¸é¾çåºï¼æµè¡ç移å¨ç«¯å¼åæ¡æ¶é½æ¯å½å¤å¼åè å± å¤ã
- å¯é¢è§çåå¹´å ï¼è¿ä¸¤è å°é¿æ并åï¼å®æ¹åºæ¬ä¸åæ´æ°widgetèæ¯ä¸»æ¨qmlï¼æå³çå°æ¥å¯¹qmlçæ§è½ä¼ååªå¢ä¸åï¼æªæ¥è¶å¿æ¯qmlã
- 没æç¼ç¨ç»éªçæ°æqmlå¦ä¹ ææ¬æ´ä½ï¼èä»VB/VCçä¼ ç»è½¯ä»¶å¼å转è¿æ¥çä»ä¸è æ´éåå¦ä¹ widgetã
- æçæ¶åä¸ç¦è¦é®ï¼æ¢çwidgetä½çqmlï¼å¦ä¹ ææ¬åéæ©åå¤äºï¼å ¶å®è¿æ£æ¯åè¿ä¸ªä¸ççå²å¦ä¸æ ·ï¼ä¸çæ¯ç®åçåæ¯å¤æçã为äºéåºåç§éæ±å满足éè¦ã
- æ»ä¹ï¼æ 论qmlè¿æ¯widgetï¼åæ¾èå©ä¸æ ·ï¼éåèªå·±çå°±æ¯æ好çï¼èªå·±æ é¿åªä¸ªå°±ç¨åªä¸ªã
- å¦æè¿ä¸ç¥éæ é¿åªä¸ªï¼æ空就两个é½å¦ï¼å¦ä¹ è¿ç¨ä¸èªå·±å°±ä¼æå身æåå对æ¯ï¼è½è å¤å³å¤å¤çåãè½å¤é¡ºå©çæå¿«çå®æèæ¿çä»»å¡ç»èæ¿èµé±ææ¯çéã
- ç½åè¡¥å ï¼å¦æä½ ç软件æç»æ¯æææä½çå¤ï¼å°±ç¨qmlï¼å¦ææ¯é¼ æ æä½çå¤ï¼å°±éæ©widgetã
-
åç¨åºè¿ç¨ä¸åç°é®é¢ï¼æ¯å¦æäºé®é¢æ¯æ端ç¹æ®æ åµä¸åºç°ï¼æ好æ¾å°é®é¢çæ ¹æºï¼ææ¶åè¯å®å¤å¤å°å°ä¼æçæ¯ä¸æ¯Qtæ¬èº«çé®é¢ï¼æçæ¯å¯¹çï¼ä½æ¯99.9%çé®é¢æç»è¯å®ä¸æ¥è¿æ¯èªå·±ç代ç åçä¸å¤å¥½å¯¼è´çï¼å¦æ为äºèµ¶æ¶é´èæ¿å¬çæ¥ï¼å®å¨ä¸è¡åç¨éå¯æè å¤ä½å¤§æ³ï¼æ¯å¦æ个å®æ¶å¨ã线ç¨ãç½ç»éä¿¡å¥çå»æ£æµç¨åºæ¯å¦æ£å¸¸ï¼ç¨åºä¸æ个模åæè åè½æ¯å¦æ£å¸¸ï¼ä¸æ£å¸¸å°±å¤ä½ç¨åºæè éå¯ç¨åºï¼å¨åµå ¥å¼ä¸è¿å¯ä»¥æ´æ´åä¸ç¹å°±æ¯ç³»ç»éå¯åæçµéå¯ã
-
åç¨åºè¿ç¨ä¸å°¤å ¶è¦æ³¨æ32ä½çåºå64ä½çåºäºä¸å ¼å®¹ï¼æ¯å¦32ä½çç¨åºå¼ç¨64ä½çåºï¼64ä½çç¨åºå¼ç¨32ä½çåºï¼é½æ¯ç¼è¯éä¸è¿çï¼èå¨windows64ä½ç³»ç»ä¸æ¯è½å¤è¿è¡32ä½ç¨åºçï¼å 为64ä½çç³»ç»æä¾äº32ä½çè¿è¡ç¯å¢ï¼ä¸è¬ç®å½å¨Program Files(x86)ï¼32ä½çç¨åºå¨64ä½çç¯å¢ä¸æç»å¼ç¨çè¿æ¯32ä½çåºãå ³äºå¦ä½å¤æèªå·±çQtåºæ¯å¤å°ä½ï¼æ个误åºå°±æ¯å¾å¤äººè¦ä¹çæäºQtCreatorçå ³äºä¿¡æ¯ä¸ååºçä½æ°ï¼è¦ä¹ä»¥ä¸ºèªå·±æ¯64ä½çç³»ç»å°±è®¤ä¸ºæ¯64ä½çQtï¼æç»è¦å¨Qtæ建å¥ä»¶ä¸æ¥çå ·ä½ä½æ°ï¼å¤§æ¦ä»Qt5.14å¼å§åºæ¬ä¸å¾å°æä¾32ä½çåºï¼å°¤å ¶æ¯Qt6.0以ååºæ¬ä¸é»è®¤å°±æ¯åªæ64ä½çåºäºï¼è¿ä¹æ¯é¡ºåºæ¶ä»£æ½®æµï¼æ¯ç«ä¸ä¹ çå°æ¥ï¼ä¸ªäººé¢è®¡2030年以åï¼åºæ¬ä¸32ä½çç³»ç»å æ¯ä¸è¶ è¿1%ï¼æ¾å¿å¤§èçç¨64ä½çåºå§ï¼æå¼ç¦äººç32ä½ä»¥åXPç³»ç»ã
-
å ³äºç¨åºä¸å¨æåéæçä¸ç¹ä¸ªäººç解ï¼
- å¨Qtç¨åºä¸ï¼åå¨æåºçæ¬çQtåéæåºçæ¬çQtã
- å®æ¹é»è®¤æä¾çäºè¿å¶å å°±æ¯å¨æåºçæ¬çQtï¼å¦æèªè¡ç¼è¯åç¼è¯çæ¶å对åºåæ° -sharedã
- éæåºçæ¬çQtéè¦èªè¡ç¼è¯ï¼ç¼è¯çæ¶å对åºåæ° -staticï¼ï¼ç论ä¸æ 论åä¸éåä¸ä½¿ç¨Qtéæåºéè¦æ¶è´¹ï¼å 为éæç¼è¯åé½çä¸å°Qtçç¸å ³åºæ件ï¼ã
- 使ç¨å¨æåºçQtæ¯æç¼è¯çæå¨æåºåéæåºï¼CONFIG += staticlibï¼çç¨åºã
- 使ç¨å¨æåºçQtç¨åºæ¯æå¨æåºçå¼ç¨ï¼å¼ç¨çæ¶å LIB += ï¼è¿è¡çæ¶åéè¦å¨æåºæ件æ¯å¦ .dll .so æ件æ¯æï¼ã
- 使ç¨å¨æåºçQtç¨åºæ¯æéæåºçå¼ç¨ï¼å¼ç¨çæ¶å LIB += ï¼è¿è¡çæ¶åæ éåºæ件æ¯æï¼å¯ä»¥ç解为该æ件已ç»åå¯æ§è¡æ件åäºä¸ºä¸ï¼ç¼ºç¹æ¯å¯æ§è¡æ件ä½ç§¯å大ï¼ã
- éè¿çææ件ç个æ°å大å°å¯ä»¥åç°ï¼éæåºç¸å½äºæè¿è¡æ¶éè¦çæ件ä¹ä¸å¹¶å并å°ä¸ä¸ªæ件äºï¼èå¨æåºæ¯æåæ两个æ件ï¼ä¸ä¸ªç¨äºç¼è¯ï¼ä¸ä¸ªç¨äºè¿è¡ã
- ä¸è¿°å¨æåºçè§åä¹éç¨äºéæåºã
- æ¤è§ååºè¯¥æ¯éç¨äºå ¶ä»è¯è¨æ¡æ¶ã
- å¾å¤äººæ个误åºå æ¬å å¹´åçæï¼ä»¥ä¸ºè¦ç¨Qtç¼åéæåºå°±å¿ é¡»ç¨éæçQtåºï¼å ¶å®å¨æåºçQtä¹å¯ä»¥ç¼åéæçåºï¼åªæ¯è¯¥åºä¸ä¼çæå¨æåºæ件ã
- å¦æè¦å°Qtç¨åºç¼è¯æéæçå¯æ§è¡æ件ï¼å个æ件æ ä¾èµï¼ï¼åææ¯æç¨çQtåºå¿ é¡»éæçã
-
åæçQtçæ¬ï¼å¤§è´ä»5.15å¼å§ï¼å°±ä¸å¨æä¾ç¦»çº¿çæ¬ä¸è½½ï¼éè¦èªè¡éè¿å¨çº¿å®è£ å¨å®è£ ï¼ç±äºé»è®¤æå¡å¨å¨å½å¤ï¼å¾å¤äººåæ ä¸è½½çæ¶åå¾æ ¢ï¼æè éæ©æä¸çæ¶åä¸è½½è¦å¿«å¾å¤ï¼ä¸ºäºè§£å³è¿ä¸ªç¦äººçé®é¢ï¼ä¸è³äºæ¶é´é½æµªè´¹å¨æ²¡ææä¹ççå¾ ä¸ï¼æ个æå ¶ç®åçæ¹æ³å¯ä»¥å°é度æåå ä¸åï¼çè³å²åä½ ç硬çãå ä¸è½½ Fiddler5ï¼å°½ééæ©ä¸æçæ¬ä¸ç¶å°ç½çä¸æï¼ï¼åå»æå¼ç¨åºåï¼å¯è½win10èªå¸¦çææ¯è½¯ä»¶ä¼æ¥æ¯å é¤ï¼ä¸´æ¶åç¨ææ¯è½¯ä»¶æè æ¢å¤å¯ä¿¡ä»»æ件å³å¯ï¼ï¼å¨åºé¨çè¾å ¥æ ä¸è¾å ¥ urlreplace download.qt.io mirrors.ustc.edu.cn/qtproject/ å车åºç¨ï¼ç¶ååå»æå¼å®è£ å¨å¨çº¿å®è£ ï¼ä¸ççªç¶åå¾é常ç¾å¥½ã
-
Qtç»å¯¹æ¯ä¸ªé常çé¼ç项ç®ï¼æºç é常åºå¤§ï¼èä¸å模å设计ï¼å¯¹äºæ足å¤ç²¾åçå¯ä»¥è±æ¶é´å¦ä¹ æºç ä¸çå ·ä½å®ç°ï¼å¦ææ¶é´ä¸å¤ï¼ä¸ªäººæ¨èç QObjectãQWidgetãQPainterãQStringãQColorãQListãQVariantãQAbstractButtonãQAbstractItemModelãqnamespace.hï¼æ´ä¸ªQtä¸ææçå ¨å±çæ举å¼ï¼ãè¿äºç±»çæºç å³å¯ï¼ççä»ä»¬æåªäºæ¹æ³åå±æ§ï¼å¯¹èªå·±çç¼ç¨ä¼æè«å¤§ç帮å©ã
-
æåä¸æ¡ï¼çç±çå½ï¼è¿ç¦»ç¼ç¨ãç¥å¤§å®¶å¤´åæµå¯ï¼ç¡ç è¯å¥½ï¼æ 绪稳å®ï¼è´¢å¯èªç±ï¼
8 æä¸æå «
8.1 æ¨èå¼æºä¸»é¡µ
å称 | ç½å |
---|---|
Qt/C++å¦ä¹ é«çº§ç¾¤ | 751439350 |
QtWidgetå¼æºdemoéå | https://gitee.com/feiyangqingyun/QWidgetDemo |
QtQuick/Qmlå¼æºdemoéå | https://gitee.com/jaredtao/TaoQuick |
QtQuick/Qmlå¼æºdemoéå | https://gitee.com/zhengtianzuo/QtQuickExamples |
8.2 æ¨èç½ç«ä¸»é¡µ
å称 | ç½å |
---|---|
qtcn | http://www.qtcn.org |
è±åçç©ºé´ | https://www.devbean.net |
yafeilinux | http://www.qter.org |
feiyangqingyun | https://blog.csdn.net/feiyangqingyun |
Qtä½åå¤§å ¨ | https://qtchina.blog.csdn.net/article/details/97565652 |
é¾å»ºæ³¢ | https://gongjianbo1992.blog.csdn.net/ |
ä¹æé¦2å· | http://blog.csdn.net/taiyang1987912 |
foruok | http://blog.csdn.net/foruok |
jason | http://blog.csdn.net/wsj18808050 |
æåæå « | http://www.cnblogs.com/swarmbees |
BIG_C_GOD | http://blog.csdn.net/big_c_god |
å ¬åäºç | https://qtdebug.com/qtbook |
é¨ç°å¥ | https://blog.csdn.net/ly305750665 |
éå¤©ä½ | https://blog.csdn.net/zhengtianzuo06 |
å¯å±±-å± å£« | https://blog.csdn.net/esonpo |
åè¡ä¸å°çª | http://blog.csdn.net/goforwardtostep |
æ¶å¥çç¥ä¹ä¸æ | https://zhuanlan.zhihu.com/TaoQt |
Qtå | https://blog.csdn.net/nicai_xiaoqinxi |
8.3 æ¨èå¦ä¹ ç½ç«
9 书ç±æ¨è
- C++å ¥é¨ä¹¦ç±æ¨èãC++ primer plusãï¼è¿é¶ä¹¦ç±æ¨èãC++ primerãã
- Qtå ¥é¨ä¹¦ç±æ¨èéäºé£çãQt Creatorå¿«éå ¥é¨ãï¼Qtè¿é¶ä¹¦ç±æ¨èå®æ¹çãC++ GUI Qt4ç¼ç¨ãï¼qml书ç±æ¨èãQt5ç¼ç¨å ¥é¨ãï¼Qtçµå书强çæ¨èãQt5.10 GUIå®å ¨åèæåãã
- 强çæ¨èç¨åºåèªææåãä¿®å »ãè§åç³»å书ãèµ°åºè½¯ä»¶ä½åãã大è¯ç¨åºåããç¨åºåçæé¿è¯¾ãã解忧ç¨åºåãï¼åçåªæµ ï¼åçç»çï¼
Top Related Projects
Qt5 super module
a cool QtQuick component library (一套酷炫的QtQuick基础库)
A new, customizable Arduino NMEA parsing library
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot